输入输出格式有要求没有
你题目的解答代码如下:
def func():
section1 = {'A':0,'B':0,'C':0}
section2 = {'A':0,'B':0,'C':0}
for i in range(10):
while True:
g = input(f"第一部分第{i+1}名学生打分:").strip().upper()
if g in section1.keys():
break
print("输入错误,请重新输入")
section1[g] += 1
for i in range(10):
while True:
g = input(f"第二部分第{i+1}名学生打分:").strip().upper()
if g in section2.keys():
break
print("输入错误,请重新输入")
section2[g] += 1
print(f'第一部分有{section1["A"]/10:.2%}的A学生,{section1["B"]/10:.2%}的B学生,{section1["C"]/10:.2%}的C学生')
print(f'第二部分有{section2["A"]/10:.2%}的A学生,{section2["B"]/10:.2%}的B学生,{section2["C"]/10:.2%}的C学生')
if section1["A"]>section2["A"]:
print('第一部分有更多的A')
elif section2["A"]>section1["A"]:
print('第二部分有更多的A')
else:
print('两部分的A一样多')
while True:
func()
if input("你想重复吗?(y/n)").strip().lower()=="n":
break
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
