下面有一個包含while循環的小代碼。raw_input()停止無限while循環嗎?
question = raw_input("How are you? > ")
state = True
number = 0
print "Hello"
while True:
if question == "good":
print "Ok. Your mood is good."
state = False
question_2 = raw_input("How are you 2? > ")
elif question == "normal":
print "Ok. Your mood is normal."
elif question == "bad":
print "It's bad. Do an interesting activity, return and say again what your mood is."
else:
print "Nothing"
如果我在「正常」,該程序將打印好的類型。你的心情很正常。無數次。
但是,如果我輸入「好」,程序打印好的。你的心情很正常。並打印question_2的內容。
爲什麼question_2 = raw_input("How are you 2? > ")
中的問題無法重複無數次?
是否有理由得出結論raw_input()
停止任何無限的while循環?
這聽起來很奇怪,你確定它是'while true:'而不是'while state:'? – alfasin
是的。我還沒有結束這個代碼,狀態是爲了其他步驟。 –