Python为什么我在这里没有输出
问题描述:
我开始学习python。 这里有什么问题? 为什么我没有得到任何输出Python为什么我在这里没有输出
感谢,并通过使用return
你的函数做任何事情之前,我的英文不好
def countdown():
i=5
while i > 0:
return i
i -= 1
print (i)
答
由于@alfasin在评论中说,你拯救功能的遗憾。
什么你可能打算做的是:
def countdown():
i = 5
while i > 0:
print(i)
i -= 1
return i
然后调用函数:
countdown()
输出:
5
4
3
2
1
+0
非常感谢你们的帮助 –
+0
谢谢你的帮助 –
'返回i'的第一次迭代之前捞出结束 – alfasin