rounds = input()
for i in range(int(rounds)):
score = input(int())[0:3]
a = score[0]
d = score[2]
antonia = 100
david = 100
for scores in score:
if a < d:
antonia -= int(a)
if a > d:
david -= int(d)
elif a == d:
pass
print(antonia)
print(david)
输入期望: 输入的第一行包含整数n(1≤n≤15),即 将被播放。在接下来的n行中,每行都是两个整数:那一轮的安东尼娅掷骰子, 接着是空格,接着是那一轮的大卫掷骰子。每次掷骰都是整数 介于1和6之间(包括1和6)。在
输出期望:输出将由两行组成。在第一行,输出Antonia拥有的点数 在所有回合结束后。在第二行,输出David拥有的点数 在所有回合结束后。在
输入:
4
56
输出:
为什么底部值(david)会正确更改,而顶部却没有??我对安东尼娅做了什么不同的事情,使得它不能输出和david相同的函数?
在第一个循环中,不断更新}。因此,在循环的末尾,}只具有与最后一组输入相对应的值。在
a
和{a
和{此外,在您的第二个循环中,您不会迭代所有的分数,而是最后一组输入。在进一步讨论之前,我建议您回过头来了解代码的具体操作,并跟踪值是如何变化的。在
无论如何,解决问题的一种方法是:
相关问题 更多 >
编程相关推荐