0
我想寫一個if語句,如果用戶輸入「是」遊戲運行,但當我無法弄清楚如何做到這一點,我無法在網上找到它。在if語句中調用函數?
userName = input("Hello, my name is Logan. What is yours? ")
userFeel = input("Hello " + userName + ", how are you? ")
if userFeel == "good":
print ("That's good to hear")
elif userFeel == "bad":
print ("Well I hope I can help with that")
q1 = input("Do you want to play a game? ")
if q1 == "yes":
print ("Alright, lets begin")
import random
print ("This is a guessing game")
randomNumber = random.randint(1, 100)
found = False
yes = "yes"
while not found:
userGuess = input('Your Guess: ') ; userGuess = int(userGuess)
if userGuess == randomNumber:
print ("You got it!")
found = True
elif userGuess>randomNumber:
print ("Guess Lower")
else:
print ("Guess Higher")
elif game == "no":
print ("No? Okay")
q2 = input("What do you want to do next? ")
什麼不起作用? –
您正在定義函數'game',但隨後將'game'重新分配給用戶輸入 – Wondercricket
修復縮進,在Python中正確使用縮進至關重要。 – Barmar