好的,所以,我试图做一个“猜数字”游戏,一个游戏,你说一个数字,另一个玩家说“下”或“更高“取决于你的答案,并且当你正确地猜出你的号码时,你就赢了。TypeError:'int'对象不可调用Python 3
也许这已经回答了,但我无法弄清楚什么是错的。
我不明白,如果在你自己调用的函数内,它应该再次运行自己,对吧?
不知道是否有帮助,但我使用Python 3
number = 897
attempts = 0
def guess():
guess = input("Number: ")
guess = int(guess)
global attempts
if guess > number:
print("It's lower.")
attempts = attempts + 1
guess()
elif guess < number:
print("It's higher.")
attempts = attempts + 1
guess()
else:
print("Correct! The number was " + str(number) + "!")
print("It took you " + str(attempts) + "!"),
print("I'm thinking of a number, guess it!")
guess()
请改变你的函数名...... –
您有一个名为'guess'功能,以及一个名为变量'guess' ......“猜测”可能会发生什么.. – donkopotamus