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)
Input Expectation: The first line of input contains the integer n (1 ≤ n ≤ 15), which is the number of rounds that will be played. On each of the next n lines, will be two integers: the roll of Antonia for that round, followed by a space, followed by the roll of David for that round. Each roll will be an integer between 1 and 6 (inclusive).
Output Expectation: The output will consist of two lines. On the first line, output the number of points that Antonia has after all rounds have been played. On the second line, output the number of points that David has after all rounds have been played.
Input:
4
5 6
Output:
Why is the bottom value(david) changed as it should correctly, but the top is not?? What am I doing different for antonia thats making it not output the same function as david?
Within your first loop, you continuously update a
and d
. So, at the end of the loop, a
and d
simply have the values corresponding to the last set of input.
Additionally, within your second loop, you are not iterating over all the scores, but rather the very last set of input. Before going any further, I would suggest you go back and understand what exactly your code is doing and trace how values change.
In any case, one way to solve your problem is:
rounds = input("Number of rounds: ")
scores = []
for i in range(int(rounds)):
score = input("Scores separated by a space: ").split()
scores.append((int(score[0]), int(score[1]))) #Append pairs of scores to a list
antonia = 100
david = 100
for score in scores:
a,d = score # Split the pair into a and d
if a < d:
antonia -= int(a)
if a > d:
david -= int(d)
elif a == d:
pass
print(antonia)
print(david)