代码与分支

时间:2017-09-24 10:22:07

标签: python-3.x

def which_prize():
    return "Congratulations! You have won a [prize name]!"
    if Points ==0  or Points ==50:
       print("Congratulations! You have won a [wooden rabbit]!")
    elif Points ==0  or Points ==150:
       print("Congratulations! You have won a [no prize]!")
    elif Points==151  or Points ==180:
       print("Congratulations! You have won a [wafer-thin mint]!")
    elif Points ==181  or Points ==200:
       print("Congratulations! You have won a [penguin]!")

    else:
        print("Oh dear, no prize this time.")

which_prize()的输入将是点数(整数)。函数which_prize()应该返回文本"祝贺!你赢了[奖品名]!"如果他们赢得了奖品和文字,那么奖品名称包括在内。哦,亲爱的,这次没有奖品。"如果没有奖品。与往常一样,测试您的功能以检查它是否正常运行。

IndentationError: unindent does not match any outer indentation level.

1 个答案:

答案 0 :(得分:1)

你可能正在混合制表符和空格。 尝试取消您的代码并仅使用制表符(或空格)再次缩进

PS:您希望如何运行代码:函数在return语句之后结束。

尝试:

def which_prize():
  if Points and Points <=50:
     return("Congratulations! You have won a [wooden rabbit]!")
  elif Points <= 150:
     return "Congratulations! You have won a [no prize]!")
  elif Points <= 180:
     return "Congratulations! You have won a [wafer-thin mint]!")
  elif Points > 180:
     return "Congratulations! You have won a [penguin]!")
  else:
      return "Oh dear, no prize this time."