I am learning Python at the moment and I have hit an issue.
Observe this code:
while 1:
print "How many lines do you want to add to this file?"
number_of_lines = raw_input(">").strip()
if not(number_of_lines.isdigit()) or number_of_lines > 10:
print "Please try a number between 1 and 10 inclusive."
continue
The code asks a user for a number, and checks it’s validity. However for some reason, the code always displays the error, even if the user does enter a valid number less than 10.
I have probably made a small error somewhere but I can’t figure it out… being a python novice!
Hope you can help! Thanks in advance.
When returned from
raw_input, yournumber_of_linesvariable is a string. You need to convert it to an integer before comparing with 10: