首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >包含分支的代码

包含分支的代码
EN

Stack Overflow用户
提问于 2017-09-24 18:22:07
回答 1查看 127关注 0票数 0
代码语言:javascript
运行
复制
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.

EN

回答 1

Stack Overflow用户

发布于 2017-09-24 20:34:17

你可能把制表符和空格混在一起了。尝试取消缩进您的代码,并仅用制表符(或空格)再次缩进。

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

尝试:

代码语言:javascript
运行
复制
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."
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46389009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档