我的代码:
team = ['barca', 'madrid']
fav_team = raw_input('What is your favorite team: ')
fav_team = fav_team.upper()
if fav_team in team:
print "AWESOME"
您好。我对编程很新,我没有经验,我正努力做这项工作。但是,当我运行此代码时,它不打印任何东西。我希望能够让用户输入他最喜欢的球队,并打印出一些东西。但没有任何结果。我怎样才能显示print语句?我已经尝试过使用输入功能但是没有用。
答案 0 :(得分:2)
你需要调用较低的功能。
team = ['barca', 'madrid']
fav_team = raw_input('What is your favorite team: ')
fav_team = fav_team.lower()
if fav_team in team:
print "AWESOME"
答案 1 :(得分:1)
team = ['barca', 'madrid']
fav_team = raw_input('What is your favorite team: ')
fav_team = fav_team.lower() #make upper lower
if fav_team in team:
print "AWESOME"
您需要将upper
lower
作为列表包含较低中的元素。
如果列表中包含大写,则仍会出现错误。所以要两个小写。
if fav_team in map(str.lower,team):
print "AWESOME"