actually it's better to have minimal number of lines in the try block, i.e. where you expect the error. Also, the input must be inside the loop (otherwise, why would you have a loop at all, if you break out in any case):
while True : age = input('please enter your age: ') try: age = int(age) except ValueError: print('that can\'t be your age') continue if age > 0 and age < 90: print("You are", age, "years old!") elif age > 90: print('you are too old!') breakor using
else
while True : age = input('please enter your age: ') try: age = int(age) except ValueError: print('that can\'t be your age') else: if age > 0 and age < 90: print("You are", age, "years old!") elif age > 90: print('you are too old!') break
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs