我正在學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