首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >集合中几个问题的知识测验

集合中几个问题的知识测验
EN

Stack Overflow用户
提问于 2022-09-18 22:12:49
回答 1查看 37关注 0票数 -6

我想增加更多的问题到知识问答程序,我在这一点上被困。从这段代码中可以看出,知识问答由一个问题组成,在一个集合中进行总结。行星={“水星”、“金星”、“地球”、“火星”}

例如,想在一个集合中对更多的问题进行分组和查询,例如: europäischen_union ={‘比利时’,‘保加利亚’,‘德国’,'Frankreich'} dax_companies ={‘阿迪达斯’,‘空中巴士’,‘安联’,‘巴斯夫’等等……

代码语言:javascript
运行
复制
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')

如果有人能像我上面描述的那样在这里添加代码,那将是非常有帮助的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-18 22:45:31

你可以这样做:

代码语言:javascript
运行
复制
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')
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73766727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档