简单倒计时Python

2024-04-27 19:46:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了这段代码,我在《傻瓜的Python》一书中找到了

countdown = 10
while countdown:
    print countdown,
    countdown -= 1
print "Blastoff!"

它应该打印10 9 8 7 6 5 4 3 2 1发射!

当我运行程序时,我得到一个错误“在打印调用中缺少括号”

在youtube上我发现了一个类似的代码,从0到10000000。这个很好用。

def count(x):
while (x <= 10000000):
    print (x)
    x+=1
count(0)
print ("I hate my job. I quit!")

他们怎么看起来这么不一样?我需要什么样的基本知识才能理解这一点?这是不同python版本的问题吗?《傻瓜的Python》是一本坏书吗?


Tags: 代码程序youtubemydefcount错误job