Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
45 lines (30 loc) · 1.19 KB

File metadata and controls

45 lines (30 loc) · 1.19 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def get_user_input(start, end):
"""
input: two integer values
lower limit 'start' and maximum 'end'
the arguments aren't inclusive.
output: if reading successful then returns the read integer.
purpose: reads from command-line a integer in the given bounds.
while input invalid asks user again
"""
loop = True # controls while-loop
while loop:
try:
# reads and converts the input from the console.
user_input = int(input("Enter Your choice: "))
# checks whether input is in the given bounds.
if user_input > end or user_input < start:
# error case
print("Please try again. Not in valid bounds.")
else:
# valid case
loop = False # aborts while-loop
except ValueError:
# error case
print("Please try again. Only numbers")
return user_input
x = get_user_input(1, 6)
print(x)
# Asks user to enter something, ie. a number option from a menu.
# While type != interger, and not in the given range,
# Program gives error message and asks for new input.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.