你好hullo! 我正在研究计算输入分数并输出分数百分比和字母分数的程序。虽然字母分级部分非常简单,但我无法使while循环正确完成。 目前,我试图通过让用户只输入0到10之间的整数来添加一个输入陷阱。问题是,只要用户输入必要的输入,它就会循环并返回输出`“请输入一个整数。“连续循环虽然变量不是一个整数
print ("Enter the homework scores one at a time. Type \"done\" when finished.")
hwCount = 1
strScore = input ("HW#" + str (hwCount) + " score: ")
while (strScore != int and strScore != "done") or\
(strScore == int and (strScore < 0 or strScore >10)):
if strScore == int:
input = int (input ("Please enter a number between 0 and 10."))
else:
print ("Please enter only whole numbers.")
#End if
strScore = float (input ("enter HW#" + str(hwCount) + " score:
所以,我可能会觉得很愚蠢,一旦我知道了这一点,但我很难过。算法的溶液状态 循环while(strScore不是整数和strScore!= “完成”)或 (strScore是整数,(strScore < 0或strScore> 10)))
提前感谢!
你绝对应该看看Python风格指南[PEP 8](https://www.python.org/dev/peps/pep-0008/)。 – brianpck
1)'input'值总是一个字符串。 2)如果您想比较类型,请使用'type(strScore)'。 –