我想增加更多的问题到知识问答程序,我在这一点上被困。从这段代码中可以看出,知识问答由一个问题组成,在一个集合中进行总结。行星={“水星”、“金星”、“地球”、“火星”}
例如,想在一个集合中对更多的问题进行分组和查询,例如: europäischen_union ={‘比利时’,‘保加利亚’,‘德国’,'Frankreich'} dax_companies ={‘阿迪达斯’,‘空中巴士’,‘安联’,‘巴斯夫’等等……
planeten = {'Merkur', 'Venus', 'Erde', 'Mars'}
planetenx = {''}
richtige = 0
versuche = 0
print('List all the planets in our solar system!')
while planeten != set():
eingabe = input('Planet: ')
if eingabe in planeten and eingabe not in planetenx:
planeten = planeten - {eingabe}
planetenx.add(eingabe)
print('Richtig!')
print(planetenx)
richtige += 1
versuche += 1
elif eingabe not in planeten and eingabe in planetenx:
print('Sorry!', eingabe, 'we already had')
versuche += 1
else:
print('Sorry!', eingabe, 'is not a planet')
versuche += 1
print('Congratulations. You have listed all the planets.')
print(richtige, 'richtige Antworten, in ', versuche, 'Versuchen')
如果有人能像我上面描述的那样在这里添加代码,那将是非常有帮助的。
发布于 2022-09-18 22:45:31
你可以这样做:
fragen = ['List all the planets in our solar system!',
'List all countries in the European Union!',
'List all DAX companies!']
antwortsätze = [{'Merkur', 'Venus', 'Erde', 'Mars'},
{'Belgien', 'Bulgarien', 'Deutschland', 'Frankreich'},
{'Adidas', 'Airbus', 'Allianz', 'BASF'}]
for frage, antworten in zip(fragen, antwortsätze):
antwortenx = set()
richtige = 0
versuche = 0
print(frage)
while antworten:
eingabe = input('Answer: ')
if eingabe == '':
continue
elif eingabe in antwortenx:
print('Sorry!', eingabe, 'we already had')
elif eingabe in antworten:
antworten.remove(eingabe)
antwortenx.add(eingabe)
print('Richtig!')
print("Korrekte Antworten:", ', '.join(antwortenx))
richtige += 1
else:
print('Sorry!', eingabe, 'is not correct')
versuche += 1
print('Question Complete.')
print(richtige, 'richtige Antworten, in ', versuche, 'Versuchen')
https://stackoverflow.com/questions/73766727
复制相似问题