ユーザーがプログラムの最後に停止できるループを作成しようとしています。私はいろいろなソリューションを試しましたが、どれもうまくいきませんでした。私がすることができたのはループを作成することでしたが、私はそれを終わらせることはできません。私は最近、Pythonの学習を始めました。誰かがこの問題について私に啓発できるのであれば、私は感謝しています。無限ループ問題(Python)の終了
def main():
while True:
NoChild = int(0)
NoAdult = int(0)
NoDays = int(0)
AdultCost = int(0)
ChildCost = int(0)
FinalCost = int(0)
print ("Welcome to Superslides!")
print ("The theme park with the biggest water slide in Europe.")
NoAdult = int(raw_input("How many adults are there?"))
NoChild = int(raw_input("How many children are there?"))
NoDays = int(raw_input("How many days will you be at the theme park?"))
WeekDay = (raw_input("Will you be attending the park on a weekday? (Yes/No)"))
if WeekDay == "Yes":
AdultCost = NoAdult * 5
elif WeekDay == "No":
AdultCost = NoAdult * 10
ChildCost = NoChild * 5
FinalCost = (AdultCost + ChildCost)*NoDays
print ("Order Summary")
print("Number of Adults: ",NoAdult,"Cost: ",AdultCost)
print("Number of Children: ",NoChild,"Cost: ",ChildCost)
print("Your final total is:",FinalCost)
print("Have a nice day at SuperSlides!")
again = raw_input("Would you like to process another customer? (Yes/No)")
if again =="No":
print("Goodbye!")
return
elif again =="Yes":
print("Next Customer.")
else:
print("You should enter either Yes or No.")
if __name__=="__main__":
main()
あなたのプログラムはいつ終了するのでしょうか、代わりに何をしていますか?また、Python 3の 'print()'関数の構文をPython 2の 'raw_input()'と一緒に使っていて、いくつかの問題があります。これらの 'var = int(0)'の行は必要ありません。Pythonで変数を初期化する必要はありません。ユーザーが最初の質問に「はい」と「いいえ」のどちらにも答えない場合はどうなりますか? –
breakを使ってみましたが、ループは実行を続けました。 –
戻り値を改行に置き換えます。 – lonewaft