def count_participants(): competitions = { 1: "Python编程挑战赛", 2: "开源鸿蒙主题赛", 3: "智慧物流挑战赛" } participants = { 1: 0, 2: 0, 3: 0 }

while True:
    competition = int(input("请输入赛项编号:"))
    
    if competition == 0:
        break
    
    if competition in competitions:
        participants[competition] += 1
    else:
        print("没有此编号请重复输入")

for competition, count in participants.items():
    print(f"{competitions[competition]}:{count}人")

count_participants()

中国电子学会主办的全国青少年信息素养大赛总决赛要开始了组委会的老师要统计各个赛项报名的人数。请帮着写一个程序实现该功能:统计时输入各项编号表示对应的比赛:1:Python编程挑战赛2:开源鸿蒙主题赛3:智慧物流挑战赛0:表示录入完毕要求:一、循环执行二、当输入错误数据可以提示没有此编号请重复输入;三、当输入0后自动统计所有项目的参赛人数并输出出来;如下面的案例:输入样例:请输入赛项编号:1请输入赛

原文地址: https://www.cveoy.top/t/topic/i2K1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录