我正在学Python,并且遇到了问题。 遵守本守则:Python 2.7.2如果/或意外的行为
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
代码询问用户的数量,并检查它的有效性。然而由于某些原因,即使用户输入的有效数字小于10,代码也会显示错误。
我可能在某处发生了一个小错误,但我无法弄清楚......是一个python新手!
希望你能帮助!提前致谢。
FYI一般你应该使用'try ... except':口号是EAFP不是LBYL。 – katrielalex 2011-12-27 00:45:05
@katrielalex谢谢,我会在将来考虑这一点,但我还没有那么深入。 – Kieran 2011-12-27 13:12:39