Python Forum
RE: the working of boolean value.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RE: the working of boolean value.
#1
Hello. I don't understand how boolean works in the while loops.

I've put "started" as false (CODE 2) and when i run the code and type "Start", the condition under ELSE is printed because the condition under IF is FALSE.
But, when i type "start" again, why does the condition under False is printed.
wouldn't we go back to the start of the loop and the condition under Else would get printed.

I have the same problem when I type "Stop". (code 12)






1. Command = ""
2.started = False
3.print("type 'help' for instructions.")
4.while True:
5. Command = input("> ").lower()
6. if Command == "start":
7. if started:
8. print("CAR is on bc!!!")
9. else:
10. started = True
11. print("""
CAR STARTED!!!!!!!!!!!!!!
'STOP' to stop the car.
'QUIT' to exit.""")



12. elif Command == "stop":
13. if not started:
14. print("CAr is at rest mf!!!!")
15. else:
16. started = True
17. print("""
CAR HAS STOPPED !!!!!!!!!!!!!!!!!!!!!!!!
'START' to start the car.
'QUIT' to exit.""")



19. elif Command == "help":
20. print("""
START: to start the car
STOP: to stop the car
QUIT: to exit
""")

21. elif Command == "quit":
22. print("BYE!")

23. break
24. else:
25. print("IDK")
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020