samedi 2 avril 2022

count first list elements whith index

import random
n=[0]*7
for i in range(7):
    n[i]=random.randint(0,99)
print(*n,sep=' ')
summa=0
for i in range(7):
    if n.index(7)<4:
        summa=summa+n[i]
print(summa)

Here is my code how i can count together first 4 elements of my list all i get is that the number in n.index is not in the list can somoune help like if it outputs numbers 12 43 43 2 56 98 71 i need to count together numbers 12+43+43+2 and then i need to multiply rest numbers that are left 56, 98 and 71 I have tried puting diffrent numbers in n.index but i get the same error




Aucun commentaire:

Enregistrer un commentaire