好的,所以,我試圖做一個「猜數字」遊戲,一個遊戲,你說一個數字,另一個玩家說「下」或「更高「取決於你的答案,並且當你正確地猜出你的號碼時,你就贏了。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