2017-09-24 6 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."