我对与编程相关的一切都很陌生,刚刚完成了 python 类(class)的介绍,并试图开始几个项目。 我遇到了一些我想不通的事情。
lives=3
while lives>0:
low=raw_input("what is the lower range that you will guess? Numbers only please.")
high=raw_input("what is the higher range that you will guess? Numbers only please")
thenumber=randint(int(low),int(high))
if int(raw_input("pick an integer between %s and %s") %(low, high))==thenumber:
print "you won!"
将两个变量都设置为“1”后,它会打印“在 %s 和 %s 之间选择一个整数”而不是“在 1 和 1 之间选择一个整数”。
编辑:提交一个数字进行猜测后,我也得到了
TypeError: not all arguments converted during string formatting
请您参考如下方法:
检查括号:
raw_input("pick an integer between %s and %s") %(low, high) #bad
raw_input("pick an integer between %s and %s" % (low, high)) #good
