,我就不一一列举,但这里有几个问题是修复帮助。也许。如果您使用Python 3,请将raw_input更改为输入。
import time
def countdown(x) :
while x > 0:
print (x)
print ("")
time.sleep(1)
x = x - 1
print("BLAST OFF!")
countdownyn = raw_input ('Would You like To Start A Countdown? Y/N (CASE SENSITIVE): ')
if countdownyn == ('Y'):
x = raw_input ('Please Enter Your Designated Time To Countdown From: ')
countdown(int(x))
输出与所需的停顿:
Would You like To Start A Countdown? Y/N (CASE SENSITIVE): Y
Please Enter Your Designated Time To Countdown From: 10
10
9
8
7
6
5
4
3
2
1
BLAST OFF!
**** ****编辑
让你走得更远...:
import time
def countdown(ticks) :
for tick in range(ticks, 0, -1):
print (tick)
print ("")
time.sleep(1)
print("BLAST OFF!")
while True:
countdownyn = raw_input('Would You like To Start A Countdown? Y/N (CASE SENSITIVE): ')
if countdownyn == 'Y':
x = raw_input('Please Enter Your Designated Time To Countdown From: ')
try:
countdown(int(x))
except ValueError:
print("Please enter a valid integer")
continue
elif countdownyn == 'N':
print("Goodbye!")
break
else:
print("Please enter only Y or N")
欢迎堆栈溢出。请阅读并遵守帮助文档中的发布准则。 [最小,完整,可验证的示例](http://stackoverflow.com/help/mcve)适用于此处。在发布您的MCVE代码并准确描述问题之前,我们无法为您提供有效的帮助。 我们应该能够将发布的代码粘贴到文本文件中,并重现您描述的问题。 – Prune
'x = int(input(':'))'。 –