while True: try: age = int(input("\nPlease enter your age:")) except ValueError: print("Sorry,I can't understand what you entered.Please enter a correct number.") continue else: break if age >= 18: print("You are able to vote in the United States!") else: print("You are too young to vote in the United States!")
if value < 0: print("Sorry,your response must not be negative.") return get_non_negative_int(prompt) else: return value
def guess_number(): number = get_non_negative_int("Please enter a number to guess: (only positive integer can work,thanks!)") while True: guess = get_non_negative_int("guess the number.") if guess > number: print("You could enter a lower one.") elif guess < number: print("I think it could be higher.") else: print("Congratulations! You got it!") break