jeudi 1 décembre 2016

Why my program runs through the if loops as if it didn't check the if loops == TRUE?

The program should add all multiples of 3 and 5, up to the value passed. But instead it seems to add every number regardless of the multiple. It should return 23, but instead returns 45. Why?

def solution(number=10):
    i = 0
    c = 0
    while i < number:
        if number % 3 == 0:
            c += i
        elif number % 5 == 0:
            c += i
        i += 1

    return c

Aucun commentaire:

Enregistrer un commentaire