【发布时间】:2020-02-03 23:20:23
【问题描述】:
有没有办法在 python 3.8 中将输入放入循环中?
我想多次获得用户输入,而不必多次运行程序。
我想输入一个英雄并得到一个答案,然后能够输入另一个英雄而不用一遍又一遍地运行。
如果有人有任何建议,请告诉我。
谢谢!
"""
This program is intended to compare heroes from Marvel and DC. Enter
your
hero choice and see what hero from #Marvel or DC is most like them.
I know there are simpler ways to write this code so if anyone has any
suggestions please leave them for me
Thanks for viewing!
Only the heroes below can be entered
marvel = ['Moon Knight', 'Hyperion', 'Thor', 'Punisher', 'Jean Grey',
'Iron Man', 'Quicksilver']
DC = ['Batman', 'Superman', 'Shazam', 'Red Hood', 'Wonder Woman',
'Batwing', 'Flash']
"""
choice = str(input('Choose a hero\n'))
def hero_choose():
if choice.lower() == 'batman':
return('Moon Knight')
if choice.lower() == 'moon knight':
return('Batman')
if choice.lower() == 'superman':
return('Hyperion')
if choice.lower() =='hyperion':
return('Superman')
if choice.lower() == 'thor':
return('Shazam')
if choice.lower() == 'shazam':
return('Thor')
if choice.lower() == 'red hood':
return('punisher')
if choice.lower() == 'punisher':
return('Red Hood')
if choice.lower() == 'wonder woman':
return('Jean Grey')
if choice.lower() == 'jean grey':
return('Wonder Woman')
if choice.lower() == 'iron man':
return('Batwing')
if choice.lower() == 'batwing':
return('Iron Man')
if choice.lower() == 'flash':
return('Quicksilver')
if choice.lower() == 'quicksilver':
return('Flash')
else:
return('Your hero may not be available\nor your spelling may be
wrong.')
print(hero_choose())
【问题讨论】:
标签: python-3.x loops input