Python 3.x 我的搜索栏会打印每个变量,而不仅仅是您键入的变量

Python 3.x 我的搜索栏会打印每个变量,而不仅仅是您键入的变量,python-3.x,Python 3.x,我的搜索栏坏了 我正在为超级英雄制作一本百科全书,目前正在搜索栏上工作 对于范围为1、2的x: 选择英雄=输入选择你的英雄: 超级英雄蝙蝠侠:布鲁斯·韦恩在DC宇宙中没有任何力量 超级英雄_antman=print真实姓名:斯科特·朗·鲍尔斯:这套西装能让他改变体型,并能与蚂蚁等昆虫交流宇宙是奇迹 超级英雄_hulk=printreal name:Bruce Banner力量超群可以跨越数英里可以音速拍击宇宙是奇迹 英雄=[‘超级英雄蝙蝠侠’、‘超级英雄蚂蚁’、‘超级英雄绿巨人’] 英雄=输入选

我的搜索栏坏了

我正在为超级英雄制作一本百科全书,目前正在搜索栏上工作

对于范围为1、2的x: 选择英雄=输入选择你的英雄: 超级英雄蝙蝠侠:布鲁斯·韦恩在DC宇宙中没有任何力量 超级英雄_antman=print真实姓名:斯科特·朗·鲍尔斯:这套西装能让他改变体型,并能与蚂蚁等昆虫交流宇宙是奇迹 超级英雄_hulk=printreal name:Bruce Banner力量超群可以跨越数英里可以音速拍击宇宙是奇迹 英雄=[‘超级英雄蝙蝠侠’、‘超级英雄蚂蚁’、‘超级英雄绿巨人’] 英雄=输入选择您的项目: 如果选择英雄: 印刷英雄 其他: 印刷品身份不明
当你在列表中键入一个英雄时,它会打印列表中的每一个超级英雄,而不是只打印你键入的那个。如何使它只打印您键入的内容?

对于您想要实现的目标,我建议您使用字典

现在,您可以使用方括号中所需英雄的姓名访问口述中的信息,如下所示:

print(hero_info["batman"])
>>> real name: Bruce Wayne has no powers is in DC universe
完整的程序可以是这样的:

hero_info = {
    "batman": "real name: Bruce Wayne has no powers is in DC universe",
    "antman": "real name:Scott lang powers: suit enables him to change size and communicate with some insects like ants universe is Marvel"
    ...
}

choose_hero = input("Select your hero: ")

if choose_hero in hero_info:
    print(hero_info[choose_hero])
else:
    print("This hero is not in my database.")
hero_info = {
    "batman": "real name: Bruce Wayne has no powers is in DC universe",
    "antman": "real name:Scott lang powers: suit enables him to change size and communicate with some insects like ants universe is Marvel"
    ...
}

choose_hero = input("Select your hero: ")

if choose_hero in hero_info:
    print(hero_info[choose_hero])
else:
    print("This hero is not in my database.")