2017-12-18 96 views
1

我開始學習python。 這裏有什麼問題? 爲什麼我沒有得到任何輸出Python爲什麼我在這裏沒有輸出

感謝,並通過使用return你的函數做任何事情之前,我的英文不好

 def countdown(): 
      i=5 
      while i > 0: 
        return i 
        i -= 1 
      print (i) 
+1

'返回i'的第一次迭代之前撈出結束 – alfasin

回答

1

由於@alfasin在評論中說,你拯救功能的遺憾。

什麼你可能打算做的是:

def countdown(): 
    i = 5 
    while i > 0: 
     print(i) 
     i -= 1 

    return i 

然後調用函數:

countdown() 

輸出:

5 
4 
3 
2 
1 
+0

非常感謝你們的幫助 –

+0

謝謝你的幫助 –

相關問題