,我就不一一列舉,但這裏有幾個問題是修復幫助。也許。如果您使用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(':'))'。 –