-
Notifications
You must be signed in to change notification settings - Fork 0
/
car.py
78 lines (67 loc) · 2.89 KB
/
car.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# engine_simulation.py
import time
import random
class CarEngine:
def __init__(self):
self.is_running = False
self.rpm = 0
self.torque = 0
self.horsepower = 0
def start(self):
"""Start the car engine."""
if not self.is_running:
self.is_running = True
print("Starting the engine...")
time.sleep(1)
print("\n─────────────── Engine Started ───────────────\n")
else:
print("Engine is already running.")
def stop(self):
"""Stop the car engine."""
if self.is_running:
print("Stopping the engine...")
time.sleep(1)
self.is_running = False
print("\n─────────────── Engine Stopped ───────────────\n")
else:
print("Engine is already stopped.")
def simulate(self):
"""Simulate engine performance."""
if not self.is_running:
print("Cannot simulate. Engine is not running.")
return
# Simulate RPM, torque, and horsepower with random values
self.rpm = random.randint(1000, 7000)
self.torque = random.uniform(100, 500)
self.horsepower = random.uniform(50, 300)
# Display simulated engine metrics
print("\n═════════════════════════════════════════════")
print(f" RPM: {self.rpm} | Torque: {self.torque:.2f} Nm | Horsepower: {self.horsepower:.2f} HP")
print("═════════════════════════════════════════════\n")
time.sleep(1)
if __name__ == "__main__":
engine = CarEngine()
# Main program loop
while True:
# ASCII art menu header
print("\n╔══════════════════════════╗")
print("║ Car Engine ║")
print("╠══════════════════════════╣")
print("║ Menu: ║")
print("║ 1. Start Engine ║")
print("║ 2. Stop Engine ║")
print("║ 3. Simulate Engine ║")
print("║ 4. Exit ║")
print("╚══════════════════════════╝")
choice = input("\nEnter your choice: ")
if choice == '1':
engine.start()
elif choice == '2':
engine.stop()
elif choice == '3':
engine.simulate()
elif choice == '4':
print("\nExiting program. Goodbye!")
break
else:
print("Invalid choice. Please try again.")