2017-09-24 49 views
-1
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.

+4

你怎么能指望任何这些语句后,在函数的第一行,你'return'运行? – khelwood

回答

0

你也许混合选项卡和空间。 尝试取消缩进代码并仅使用制表符(或空格)缩进它

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."