Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

simple car start/stop sim issue

$
0
0

So I've literally just begun learning python, starting with some lengthy youtube tutorials. One tutorial wanted me to create a sim/game of starting and stopping a car. My code is very similar to the solution. I'm not sure what the problem is. The specific issue is the program fails to return the print function for when the car is already started or stopped--it just reiterates the start/stop print as if the boolean code to indicate whether the car is on or off at present doesn't exist.

start = input('Enter "help" to see instructions: ').lower()if start == 'help':    started = False    user_input = input("start - start the car\nstop - stop the car\nquit - exist program\n").lower()    while True:        if user_input == "start":            if started:                print("The car is already on.\n") #so if i enter start two times in a row, the second time it should print "The car is already on."            else:                started = True                print("The car has started. Now what?\n")        elif user_input == "stop":            if not started:                print("The car is already stopped.\n")            else:                started = False                print("The car has stopped. Now what?\n") #if this is the first command entered after "help", it should be printing "The car is already stopped." but doesn't do that.        elif user_input == 'quit':            breakelse:    print("This is not a valid command.")

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>