2016-09-15 114 views
0
races=['Imperial', 'Nord', 'High Elf', 'Wood Elf', 'Dark Elf', 'Orc', 'Argonian'] 
race_desc=['Battle worthy! Able to find a few extra gold than normal', 
     'Tough against warriors! 50% resistant to cold', 
     'Esteem in Arcane Magic! 50+ extra magicka', 
     'Masters of Archery! Increased skill in archery', 
     'Destructive at will! Increased skill in destruction', 
     'Buff and Mighty! Increased skill in two-handed weapons', 
     'Feared reptiles! Underwater breathing ability'] 
def game(): 
    print "Welcome to The Elder Scrolls: Valenwood" 
    print "Imperial, Nord, High Elf, Wood Elf, Dark Elf, Orc, Argonian" 
    user_race=raw_input("Please select a race from above: ") 
    for race in races: 
     if user_race.title() == race: 
      print "You've chosen an %s" % user_race.title() 
    #HELP HERE 

game() 

我希望用戶在輸入比賽時從race_desc列表中獲取輸出。我已經按順序分配了列表,例如:輸入:Nord,輸出:「對抗戰士......」或輸入:Argonian,輸出:「恐懼的爬行動物...」明白我的意思嗎? 所以我希望有人能夠幫助我解決這個問題。另外我正在使用python 2.6。用戶輸入打印預選列表(python 2.6)

+0

所以,你有什麼問題?你得到或沒有得到什麼錯誤? – Fallenreaper

+0

問題是我不知道如何從用戶輸入創建輸出。我能夠打印他們選擇的內容,但不能顯示與user_race輸入相關的race_desc,因爲我不知道如何去做。 –

回答

0

好吧,我得到它的工作我怎麼想它:

for i in race_desc: 
    if user_race.title() == i: 
     print "You've chosen an %s. %s" % (user_race.title(), race_desc[i][0]) 

我不得不改變race_desc成詞典:

race_desc={ 
    'Imperial' : ['Battle worthy! Able to find a few extra gold than normal'], 
    'Nord' : ['Tough against warriors! 50% resistant to cold'], 
    'High Elf' : ['Esteem in Arcane Magic! 50+ extra magicka'], 
    'Wood Elf' : ['Master of the bow! Increased skill in archery'], 
    'Dark Elf' : ['Destructive at will! Increased skill in destruction'], 
    'Orc' : ['Buff and Mighty! Increased skill in two-handed weapons'], 
    'Argonian' : ['Feared reptiles! Underwater breathing ability'] 
}