I'm old and I'm having issues to understand it (Newbie learner)

Hello, lovely people, I was trying to understand the logic behind this and I failed I do not understand how this code runs and why it runs like this for me it is making no sense.
so we have a while statement … so we ask the user to start this car and user types start the car started and after he tries to type start again he sees the message that car already started … I have a problem understand that… why we do not do this in the simple logical way?
The user typed start message appear car started
if user types again we check if the car started? if yes we show a different message
what is the purpose of the started variable? I don’t understand HOW IT IS CONNECTED TO the code at all … why do we need that variable?

started = False

while True:
command = input(" ")
if command == “start”:
if started:
print(“car already started”)
started = True
print(“Car started”)

what is stored in a started variable? it is just false so how it is connected to the car? Why did we change started variable to True in the else statement ?? it is confusing to me … and makes no logical sense … I thought python executed everything line by line … but from this, it seems not I know the code is working fine. this is logic that is logical. 1. Car started. 2. Is the car already started? Yes or not? Yes. The car already started, No, the car needs to start.

The information if the car is started. At the beginning, the car is not started → started = False.

The reson for the while-loop is not present in this code.
Generally an infinite-loop like this (while True) is meant to be a program that just keeps running and evaluate user-inputs up until an input is “end the program”. Like your browser - it just runs and waits for you to do something. Or don’t. It doesn’t care. Only if you close it, will the program actually stop → meaning it only stops when given a specific input.

The code doesn’t contain that part (yet?).
Which means the code is overall incomplete and begs the question, where you got it from. Could be a tutorial which sets up a logic to use but is still at the start and some things might only make sense later.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.