簡體   English   中英

Python 問答游戲幫助請

[英]Python quiz Game Assistance Please

我是 python 的新手,不知道為什么這不起作用。 我需要創建一個 python 測驗,他們在其中猜測與每個字母匹配的符號。 我不知道為什么,但每當我測試它時,我輸入了一個正確的答案,它說它是錯誤的。 我是 python 的新手,但我相信這相對容易修復。 任何幫助,將不勝感激

answers = {"[A,#],[B,6],[C,+],[D,""],[E,&],[F,)],[G,.],[H,!],[I,8],[J,,],[K,$],[L,3],[M,*],[N,%],[O,1],[Q,/],[R,4],[S,2],[T,:],[U,0],[V,9],[W,'],[X,5],[Y,-],[Z,7]"}

def EnterPairings():
    pairings = {"letters: [A:Z]", "symbols: [0:9], [#],[+],[/],[&],[""""""""],[*],[%],[:],[,],[$],[!],[-],[.],[']"}
    letters = input("Enter letter")
    if letters in pairings:
        print("You've already paired this wih another symbol")
        EnterPairings()
    elif letters not in pairings:
        symbols = input("Enter symbol to go with letter symbol")
        pairings = [letters, symbols]
        if pairings == answers:
            print(pairings)
            print("Well Done, that's the correct answer!")
        else:
            print(pairings)
            print("Sorry that is not the right answer")
            del pairings
    return
Menu()

def DeletePairings():
    print("")
    print("Removing a pairing")
    rename = input("Enter the letter you want to remove")
    print(pairings)
    del pairings[rename]
    print(pairings)
    return

我將從您的字典答案的定義開始。

answers = {"A":"#","B":"6",...}

然后在獲得用戶輸入后,您可以檢查

if answers[letters] == symbols:

變量“answers”和“pairings”是字典,但是字典采用str類型的鍵並返回與其關聯的值:

dictionary = {"key": "value", "other_key": "other_value"}

在這里,您創建具有巨大鍵但沒有與之關聯的值的字典,您必須與像這樣工作的類型list混淆:

simple_list = ["value", "other_value"]

我建議您尋找listdict之間的區別。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM