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