私信  •  关注

entrez

entrez 最近创建的主题
entrez 最近回复了
6 年前
回复了 entrez 创建的主题 » python决策逻辑与字典中的循环

尽管洛奇的答案可能是最简单的方法 要求 您可以使用循环,只需循环遍历字典中的每个项即可手动比较每个项:

team = input('enter team name: ')
for item in x:
  if x[item] == team:
    print(item)

如果需要显示用户是否进入城市或团队的匹配项,只需检查两项:

team = input('enter team or city name: ')
for item in x:
  if x[item] == team:
    print(item)
  elif item == team:
    print(x[item])