It looks you are confusing loops and if conditions.
Loops are used to repeat execution of a code block.
If condition is used to branch code execution (i.e. execute one block or another depending on one or more conditions).
At the moment each of the loops on lines 6-28 would try to iterate over certain range, but will break out of the loop immediately (in the first iteration). If you want to validate user input, you should use
Loops are used to repeat execution of a code block.
If condition is used to branch code execution (i.e. execute one block or another depending on one or more conditions).
At the moment each of the loops on lines 6-28 would try to iterate over certain range, but will break out of the loop immediately (in the first iteration). If you want to validate user input, you should use
if
block, not for loop. And you may wrap that if block in a while loop, e.g.:while True: age = int(input('Enter your age (1-95):')) if 1 <= age <= 95: # it is arguable why you use these boundaries, not just if age >= 0: break else: print('Not valid age') print(f'your age is {age}')
Output:Enter your age (1-95):100
Not valid age
Enter your age (1-95):25
your age is 25
Please, note that this is just an example implementation, it could be done in different ways, have more validations/error handling, etc.
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