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。
答案 0 :(得分: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']
}