试图做一个布尔测试循环,其中用户需要输入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