I am very new to programming and tried to make a age checker code, however the loop to make sure user input is a number does not work.
If a string is entered, for example hello
, the input passes the .isdigit()
condition, and messes up the last if statement.
Any help would or advice on how to construct the number checker loop properly, so that strings are not entered into the last if statement would be greatly appreciated. Here is my code:
while True:
age = input('Enter age: ')
if age.isdigit():
print('Thank you, number entered is:', age)
else:
print('A number must be entered')
break
print('Please enter age')
used_variable = age
if used_variable > 18:
print('user is older than 18')