为什么在python中使用list时会出错?

时间:2014-04-04 03:42:53

标签: python list calculator

我正在尝试执行以下CodingBat问题:no_teen_sum但在第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

1 个答案:

答案 0 :(得分:1)

存在缩进问题。记住要始终使用4个空格进行缩进,保持一致。

这是固定版本:

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