亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我的函數返回錯誤消息:'wordlist is not defined

為什么我的函數返回錯誤消息:'wordlist is not defined

達令說 2021-06-23 17:01:08
運行此程序時,我收到此錯誤消息:NameError: name 'wordList' is not defined。想不通為什么。謝謝。隨機導入定義主():def getRandomWord(wordList):    wordIndex = random.randint(0, len(wordList) -1)    return wordList[wordIndex]words = "Harry John Paul Jane Sue Frank Julie Tom Alice Sam".split()secretWord = getRandomWord(words)print("Welcome to You Bet Your Life with Groucho\n")print("Say the secret word and win a thousand dollars!")your_word = input("What is your guess for the secret word? ")if your_word == secretWord:    print("Congratulations you are correct. The secrt word is", secretWord)    print("and you win $1000 dollars !")else:    print("Sorry, that is not the secret word.")playAgain = TruewordList = secretWordplayAgain = input("Do you want to play again? (yes or y) to continue")if playAgain == "Yes" or playAgain == "y":    getRandomWord(wordList)else:    print("Ok. Goodbye.")如果名稱== ' main ': main()
查看完整描述

1 回答

?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

我看到你在重新開始游戲時遇到了麻煩。簡單地調用您的函數不會重新啟動整個游戲或將您帶回頂部,但您可以進行的一個小調整是將所有內容放入while具有這樣條件的循環中


play = 'y'

while play == 'y':


    words = "Harry John Paul Jane Sue Frank Julie Tom Alice Sam".split()

    ....


    playAgain = input("Do you want to play again? (yes or y) to continue")


    if playAgain == "Yes" or playAgain == "y":

        play = 'y'

        continue

    else:

        print("Ok. Goodbye.")

        play = 'n'

所有這一切都是,如果play的值為 ,則y游戲將重播,直到值更改為 ,n然后循環將結束,因此游戲


查看完整回答
反對 回復 2021-06-29
  • 1 回答
  • 0 關注
  • 412 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號