Junior — Middle
How can you determine the correctness of the entered age by checking the boundaries of acceptable values?
sobes.tech AI
Answer from AI
To verify the correctness of the entered age, usually the minimum and maximum allowable values are set, for example, from 0 to 120 years. The check might look like this:
age = input("Enter age: ")
try:
age_int = int(age)
if 0 <= age_int <= 120:
print("Age is correct")
else:
print("Age is outside the allowable range")
except ValueError:
print("Non-numeric value entered")
Thus, first it checks whether the entered value can be converted to a number, and then it checks whether it falls within the specified bounds.