Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
601 B
3
Indexable
Never
while True:
    try:
        age = int(input("Please enter your age: "))
    except ValueError:
        # Only print this if age is not a number
        print("Sorry, I didn't understand that.")
        continue
    if age < 0:
        #Only print this if age is negative
        print("Sorry, your response must not be negative.")
    else:
        #Only break out of the loop if age is a number AND is not negative
        break
        
if age >= 18: 
    print("You are old enough to vote in the United States!")
else:
    print("You are not able to vote in the United States.")