-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExc 03.py
More file actions
47 lines (39 loc) · 1.05 KB
/
Copy pathExc 03.py
File metadata and controls
47 lines (39 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Running a car using if, elif, else commands
# Initialize variables
command = ""
mode = "off" # Default mode is "off"
# Continuous loop to receive commands
while True:
command = input("> ").lower()
# Start the car
if command == "start":
if mode == "on":
print("The car is already running.")
else:
print("The car started...")
mode = "on"
# Stop the car
elif command == "stop":
if mode == "off":
print("The car is already stopped.")
else:
print("The car stopped.")
mode = "off"
# Show available commands
elif command == "help":
print(
"""
Start: Start the car.
Stop: Stop the car.
Exit: Exit the program.
Help: Show available commands."""
)
# Exit the program
elif command == "exit":
break
# Handle invalid commands
else:
print("Invalid command.")
# Additional check if the car is off after the loop ends
if mode == "off" and command == "stop":
print("The car is stopped.")