Introduction to while loops
command = ""
while command != "quit":
command = input("> ").lower()
if command == "start":
print("Car started...")
elif command == "stop":
print("Car Stopped.")
elif command == "help":
print("""
start - to start the car
stop - to stop the car
quit - to quit
""")
else:
print("Sorry, I don't understand that")
This is basically a car game built with the “while loop” in python programming language.
The program initially starts with an empty command. When the command entered by the user is not quit, the program is ready to accept and process inputs. If the input entered is ‘start’, then the program prints ‘car started’; if the input given is ‘stop’, then the output by the program will be ‘car stopped’; if the input given to the program is ‘quit’, then the program ends and breaks out from the loop. This is basically how the while loop works in python programming language.