試圖做一個布爾測試循環,其中用戶需要輸入10到1000之間的數字,包括10和1000,他們需要留在這循環,直到他們輸入正確的數字,然後我會完成else語句。我想返回一個「二重奏」列表中的頂級元素的數量
我嘗試這樣做:
while (num_years < 10) and (num_years > 1000): # boolean test , note == (= will give you an error!)
print("Your input must be 10 and 1000")
input("Enter number of years to simulate (currently " + str(num_years) + "): ")
else:
print()
這:
while (num_years == range(10, 1000)): # boolean test , note == (= will give you an error!)
print("Your input must be 10 and 1000")
input("Enter number of years to simulate (currently " + str(num_years) + "): ")
else:
print()
OFFTOPIC評論:從中我記得你永遠不會將你的問題標記爲答案,請參閱[this](http://stackoverflow.com/help/someone-answers)鏈接。 – MaLiN2223
提示*「您的輸入必須是10和1000」*沒有意義(一個數字不能(http://www.dictionary.com/browse/be)有兩個不同的數字......此外,即使您添加**之間**這個詞在適當的位置上,如果你想要**包含**,(10個是允許的1000個)或**獨佔**,(10個是1000個是不允許的),你仍然應該澄清。如果你在源自他們課程的python問題標記爲你的python問題的答案,那麼你在python的作者上的在線課程將會很感激,因爲他們中的大多數是(http://stackoverflow.com/users/7443013/supernova):) – shash678
between幷包括 – Supernova