gpt4 book ai didi

python - 我的初学者项目出错

转载 作者:太空宇宙 更新时间:2023-11-04 07:31:35 25 4
gpt4 key购买 nike

我对与编程相关的一切都很陌生,刚刚完成了 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

关于python - 我的初学者项目出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46260441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com