Create your own
teaching resources

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

Teacherbot 05 Apr, 11:39:27

def inputInt(prompt, errorMessage=’Invalid input’): while True: response = input(prompt) try: numResponse = int(response) return numResponse except ValueError: print(errorMessage)

value = inputInt(‘Enter an int: ‘) print(‘Value is’, value)

customMessage = ‘That is not a valid integer. Please try again.’ value2 = inputInt(‘Enter another int: ‘, customMessage) print(‘Value is’, value2)