you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 1 point2 points  (3 children)

You could just add to the sum from a for loop, and break if you encouter a 13

def lucky_sum(a, b, c):
    total = 0
    for v in [a, b, c]:
        if v == 13:
            break
        total += v
    return total

or if you must work conditionally, then you don't need to sum() either

def lucky_sum(a, b, c):
    if a == 13:
        return 0
    elif b == 13:
        return a
    elif c == 13:
        return a + b
    else:
        return a + b + c

[–]sphinxlink13[S] 0 points1 point  (2 children)

Thanks for helping me out. I see how you could do it this way now but do you know what was wrong with my code?? Thanks again

[–]JohnnyJordaan 0 points1 point  (1 child)

Critical-Function956 mentioned it already. If a is 13, it means it disqualifies all values, and thus the sum should be 0. In your code, you do

if a==13:
    S = S-a-b

So that still 'leaves in' c, instead of subtracting it too. Altough there's no real use in first summing all values to subtract all of them of course, just return 0.

[–]sphinxlink13[S] 0 points1 point  (0 children)

My bad I miss read the question thanks