gpt4 book ai didi

Python初学者输入法和不同的选择

转载 作者:行者123 更新时间:2023-11-28 18:31:00 26 4
gpt4 key购买 nike

虽然可能有更简单的方法,但我想了解哪里出了问题。当给出 super 英雄的名字时,代码应该告诉你 super 英雄的真实身份。

问题是:

在您提供 super 英雄的真实姓名后,它会询问“您需要更多信息吗?”;你如何设置这个问题的选择?

super_heros = {'Hulk': 'Bruce Banner',
'Capitan America': 'Steve Rogers',
'Spiderman': 'Peter Parker'}
hero_biography = {'Bruce Banner' : 'David Banner nasce in California...ecc'}

while True:
choice = input('Nome Supereroe:') ###Superhero's name:
if choice == 'Hulk':
print(super_heros['Hulk'])
elif choice == 'Bruce Banner':
choice = input('Desideri maggiori informazioni?') ###Do you want more information
elif choice == 'Yes': ### I know that this one will refer to : choice = input('Nome Supereroe:')
print(hero_biography['Bruce Banner'])
elif choice == 'Capitan America':
print(super_heros['Capitan America'])
elif choice == 'Spiderman':
print(super_heros['Spiderman'])
elif choice == 'Esc':
break
else:
choice == ''
print('Nome inesistente')

最佳答案

将嵌套条件与另一个变量一起使用,例如选择2

...
elif choice == 'Bruce Banner':
choice2 = input('Desideri maggiori informazioni?')
if choice2 == "Yes":
print(hero_biography['Bruce Banner'])
elif choice == 'Captain America':
...

关于Python初学者输入法和不同的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37345584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com