前提・実現したいこと
以前に質問をさせていただいたプログラムに再度問題が発生いたしました。どうしたらうまくいくのか、ネットで調べて試行錯誤しましたが、全く効果(?)がありませんでした。なぜうまくいかないのか、皆様のご意見をお聞きしたいです。問題点はコードの下に記してあります。
該当のソースコード
python
1flag = True 2while flag == True: 3 print(' MENU') #メニュー表示 4 print('==========') 5 print('S to start') 6 print('H for help') 7 print('Q to quit') 8 print('==========') 9 print(' ') 10 choice = input('Option?: ') 11 12 if choice == 'H': #このプログラムの説明 13 print('This program will give you the area of a rectangle.') 14 print('Please provide the height and width when asked.') 15 print('You can quit this program from the main menu by pressing Q') 16 elif choice == 'Q': #プログラムを終了(Quit) 17 flag = False 18 elif choice == 'S': #プログラムの開始(Start) 19 choice2 = input("please choose the number: ") 20 choice3 = int(choice2) 21 def menuList(choice3): 22 if choice3 == 0: 23 print("bad input") 24 elif choice3 == 1: #円を描く 25 import turtle 26 t=turtle.Turtle() 27 turtle._Screen() 28 elif choice3 == 2: #四角を描く 29 import turtle 30 smart = turtle.Turtle() 31 for i in range(4): 32 smart.forward(50) 33 smart.right(90) 34 turtle._Screen() 35 elif choice3 == 3: #三角形を描く 36 import turtle 37 board = turtle.Turtle() 38 board.forward(100) 39 board.left(120) 40 board.forward(100) 41 board.left(120) 42 board.forward(100) 43 turtle._Screen() 44 elif choice3 == 4: #プログラムの終了 45 print("Good bye") 46 flag = False 47 menuList(choice3) 48 else: 49 print('Not a valid choice. Only S, Q and H are valid choices') 50 51print('Program ending.')
4を選択するとプログラムを終了するようにしたいのですが、なぜかループしてしまいます。
なぜ、"flag = False"が働いていないのでしょうか。
もし、解決案が分かる方がいらっしゃいましたら、ご指摘いただきたいです。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。