Question

I am trying to do the following CodingBat problem: no_teen_sum but keep getting an error in line 2:

def no_teen_sum(a, b, c):
teens = [13,14,17,18,19]
  if a in teens:
    return b + c
  elif b in teens:
    return a + c
  elif c in teens:
    return a + b
  elif a in teens and b in teens:
    return c
  elif a in teens and c in teens:
    return b
  elif b in teens and c in teens:
    return a
Was it helpful?

Solution

There is an indentation problem. Remember to always use 4 spaces for indentation, be consistent.

Here's the fixed version:

def no_teen_sum(a, b, c):
    teens = [13,14,17,18,19]
    if a in teens:
        return b + c
    elif b in teens:
        return a + c
    elif c in teens:
        return a + b
    elif a in teens and b in teens:
        return c
    elif a in teens and c in teens:
        return b
    elif b in teens and c in teens:
        return a
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top