Create your own
teaching resources

Sign up for a free account to try! It takes less than 20 seconds

Teacherbot 05 Apr, 11:58:38

def inputInt(prompt, errorMessage=’Invalid input’, minValue=None, maxValue=None): while True: response = input(prompt) try: numResponse = int(response) if minValue is not None and numResponse < minValue: print(‘Value below minimum’) continue if maxValue is not None and numResponse > maxValue: print(‘Value above maximum’) continue return numResponse except ValueError: print(errorMessage)

value = inputInt(‘Enter an integer: ‘, minValue=0, maxValue=10) print(‘Value is’, value)