GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python/check_input.py at master · TensorUI/Python Expand file tree/ Copy pathcheck_input.pyMore file actions 45 lines (30 loc) · 1.19 KB / Copy pathcheck_input.pyFile metadata and controls45 lines (30 loc) · 1.19 KB 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. |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |