如果這是一個荒謬的問題,我很抱歉,但我只是學習python,我無法弄清楚這一點。 :)蟒蛇雖然循環故障
我的程序應該打印用戶輸入的任何狀態的資本。有時它會連續工作十次,其他時間連續工作三次,然後它會在您鍵入狀態後停止。如果我重新啓動它並輸入停止的狀態,它將工作得很好....隨機次數然後它會再次停止。我究竟做錯了什麼?我的代碼也很糟糕?我不知道使用什麼類型的代碼,所以我只是在我可以開展工作的任何地方扔掉。
x = str(raw_input('Please enter a sate: '))
while x == 'Alabama':
print 'Montgomery is the capital of', x
x = str(raw_input('Please enter a state: '))
while x == 'Alaska':
print 'Juneau is the capital of', x
x = str(raw_input('Please enter a state: '))
while x == 'Arizona':
print 'Phoenix is the capital of', x
x = str(raw_input('Please enter a state: '))
while x == 'Arkansas':
print 'Little Rock is the capital of', x
x = str(raw_input('Please enter a state: '))'
有人試圖幫助你的代碼格式化。你應該讓他們自己做,或者自己做,以便代碼實際上是可讀的。 – crashmstr 2012-07-24 17:33:11