0
import random

def calculate_score():
    worplist = [1, 1, 5]
    for worp in worplist:
        if worp == 1:
            worplist.remove(worp)
        if worp == 6:
            worplist.append(worp)
    
    

    print(sum(worplist))
calculate_score()

I want every 1 to be removed but it only removes the first one. Then if I add a 6 to the list it doesn't work at all. Any help?

kezz
  • 107
  • 1
  • 2
  • 9

1 Answers1

0

Have you tried using an "else if" instead of another "if" statement?

import random

def calculate_score():
    worplist = [1, 1, 5]
    for worp in worplist:
        if worp == 1:
            worplist.remove(worp)
        elif worp == 6:
            worplist.remove(worp)
    print(sum(worplist))

calculate_score()
kryozor
  • 315
  • 1
  • 7