我試過幾件事情來解決這個循環,它只是不會工作。至於現在它給了我一個語法錯誤,突出顯示第一個打印語句中的yes後面的引號......我沒有看到任何錯誤嗎?時髦雖然循環/時髦的語法錯誤Python 2.7
Ycount = 0
Ncount = 0
Valid = ["Y","y"]
InValid = ["N","n"]
Quit = ["Q","q"]
Uinp = ""
while Uinp != "Q":
Uinp = raw_input("Did you answer Y or N to the question(enter Q to quit)? ")
if Uinp in Valid:
Ycount = Ycount + 1
print "You have answered yes" ,Ycount, "times"
print "You have answered no" ,Ncount, "times"
elif Uinp in InValid:
Ncount = Ncount + 1
print "You have answered yes" ,Ycount, "times"
print "You have answered no" ,Ncount, "times"
elif Uinp in Quit:
break
很明顯,它也複製了滑稽....變量在我的評論結束... – Carsomyr
您的代碼適合我。 – Hoppo
什麼是給你一個語法錯誤 - 在你的編輯器中突出顯示,或者當你嘗試運行時解釋器?...你使用的是什麼版本的Python:是2.x還是3.x? –