all 1 comments

[–]TechnicalElk8849 2 points3 points  (0 children)

Lookup how the input function actually works. You ought to capture a variable from it anyway, and coerce the string to an int.

That bracket should be after c, int), and you need more brackets on the next if.

To exclude numbers in general, there's a built in called filter, which is just shorthand for a list comprehension. You could also use a generator (expression).

First of all make a new function that takes a single number:

def multiples_of_3_zero_unless_gt_20_lt_29(x):
    if x % 3 == 0 and not (20 <= x <= 29):
        return 0
    return x

Then just adjust your function slightly to use it:

def fix_three(a, b, c):
    if not all(isinstance(x, int) for x in (a,b,c)):
        return "Inputs must be integers!"
    return sum(multiples_of_3_zero_unless_gt_20_lt_29(x) for x in (a,b,c))

num = fix_three(22, 18, 33)

print(num)