0

How to make specific list print after each input with while loop?

Hello, I am trying to make this while loop repeat after each user input until (4) Abort is triggered. In other words, I am trying to make the user able to input 1,2 and 3 one after the other, receive the print response without the program terminating. So far I have only managed to make it print infinitely, which is bad. I hope I made my question clear enough. Please support me with your suggestions and simplifications. Thank you! Code playground link: https://code.sololearn.com/csFfKd3fktQN Code below: print('''Welcome commander. Starship launch sequence initiated. For list of available commands, type \"list\" ''') list = ["(1) Start engines", "(2) Turn on autopilot", "(3) Launch", "(4) Abort"] input = input("Please input your command:").lower() while input != "4": print("List of available commands:", *list, sep='\n') if input == "1": print('Starting engines...') elif input == "2": print('Turning on autopilot...') elif input == "3": print('Launch sequence engaged...') elif input == "4": print('Aborting...') else: print('Input unrecognized. Try again.')

25th May 2020, 3:44 PM
KSI đŸ€Ą
KSI đŸ€Ą - avatar
4 Answers
+ 3
last command in while loop should be input= input()
25th May 2020, 4:10 PM
Oma Falk
Oma Falk - avatar
+ 2
while True: print("List of available commands:", *commandlist, sep='\n') userinput = input("Please input your command:").lower() if userinput == "1": print('Starting engines...') elif userinput == "2": print('Turning on autopilot...') elif userinput == "3": print('Launch sequence engaged...') elif userinput == "4": print('Aborting...') break else: print('Input unrecognized. Try again.')
25th May 2020, 4:21 PM
rodwynnejones
rodwynnejones - avatar
0
Oma Falk This totally fixed it! Thank you all for your input *^_^*
26th May 2020, 11:44 AM
KSI đŸ€Ą
KSI đŸ€Ą - avatar