The following is what I have currently in python 3:
a = 0
b = 0
c = 0
M = 100
T = 100
mth = [[25,50,100], [70,50,88], [5,10,33]]
for i in mth:
m = i[0]
t = i[1]
h = i[2]
if a+m <= M:
a = a+m
M = M-m
else:
continue
if b+t <= T:
b = b+t
else:
continue
c = c + h
print(a,b,c)
My problem with the above is that it should add the first two tuples and print
95 100 188
However for some reason when the for loop reaches the second tuple in mth it checks if a+m <= M and eventhough its true at this point, it goes straight to the Else statement and ends up adding the third tuple together to give
30 60 133
I tried removing the third one, but it still skips over the second tuple. Is there something silly I'm doing here? Any help is appreciated!
Aucun commentaire:
Enregistrer un commentaire