mardi 12 février 2019

How I can sum numbers until max height?

There is height list it's total 1743 cm. I have 6 cells I want to put this numbers in cells. Max height is 300 cm. I use for loop for it it will take numbers inside height list and plus them until get closer 300 cm

height=[67, 67, 55, 65, 65, 65, 61, 58, 40, 40, 58, 53, 59, 63, 51, 57, 43, 65, 45, 65, 61, 58, 47, 58, 65, 74, 64, 28, 61, 46, 39]

max_height=300 #cm 

sum1=0
count=0

for i in height:
 sum1=height[count]+sum1

 count+=1
 if max_height>=sum1>=250:

    print(sum1)
    sum1=0
print(sum1)
print("\n",sum(height))

I expected it will get 6 sum but get 7 sum. if you run you will see (254,289,273,261,289,292,85)

Aucun commentaire:

Enregistrer un commentaire