奥运奖牌计数

所属作业: hw4 算法: 循环

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15

n = int(input())  # 输入参与决赛项目的天数
gold_total = 0  # 金牌总数
silver_total = 0  # 银牌总数
bronze_total = 0  # 铜牌总数

for _ in range(n):
    gold, silver, bronze = map(int, input().split())  # 输入每一天的金、银、铜牌数目
    gold_total += gold
    silver_total += silver
    bronze_total += bronze

medal_total = gold_total + silver_total + bronze_total  # 总奖牌数

print(gold_total, silver_total, bronze_total, medal_total)

错误代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
n=int(input())
a,b,c=input().split()
d,e,f=input().split()
g,h,i=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
e=int(e)
f=int(f)
g=int(g)
h=int(h)
i=int(i)
print(a+b+c,d+e+f,g+h+i,a+b+c+d+e+f+g+h+