[Tutor] Python Tutorial Confusion
Ricardo
icarrrdo at gmail.com
Mon Aug 24 01:08:12 EDT 2020
This is probably a very elementary question/problem to most of you, but
I’m having trouble understanding lines 5 through 10. Can someone explain
it to me?
1 command = ""
2 started = False
3 while True:
4 command = input("> ").lower()
5 if command == "start":
6 if started:
7 print("Car is already started!")
8 else:
9 started = True
10 print("Car started...")
11 elif command == "stop":
12 print("Car stopped.")
13 elif command == "help":
14 print("""
15 start - to start the car
16 stop - to stop the car
17 quit - to end the game
18 """)
19 elif command == "quit":
20 break
21 else:
22 print("Sorry, I don't understand that")
The person conducting the tutorial says line 2 means the car is NOT
started
Line 5 says if command is “start”, it prints “Car Started…” (line10)
Then, line 6 says “if started” meaning if NOT started (because started =
False in line2) then print “Car is already started!”) (line7) which I
don’t understand. Why would it print “Car is already started!” (line7) if
started = false (line2) meaning it is NOT started.
Then line 9 sets started = True and it just confuses me. Sorry for such a
beginner question.
More information about the Tutor
mailing list