-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
104 lines (89 loc) · 3.38 KB
/
Copy pathinterface.py
File metadata and controls
104 lines (89 loc) · 3.38 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from mypython import Car, CarManager
def main_menu():
"""Display the main menu options"""
print("\n=== Car Manager System ===")
print("1. Add a new car")
print("2. Remove a car")
print("3. List all cars")
print("4. Start a car")
print("5. Stop a car")
print("6. Find a car")
print("7. Exit")
print("=" * 27)
def get_car_details():
"""Get car details from user input"""
make = input("Enter car make: ").strip()
model = input("Enter car model: ").strip()
year = int(input("Enter car year: "))
color = input("Enter car color: ").strip()
return make, model, year, color
def get_car_search_details():
"""Get make and model for car search"""
make = input("Enter car make: ").strip()
model = input("Enter car model: ").strip()
return make, model
def run_car_manager():
"""Main function to run the car manager interface"""
manager = CarManager()
while True:
main_menu()
try:
choice = input("Enter your choice (1-7): ").strip()
if choice == "1":
# Add a new car
try:
make, model, year, color = get_car_details()
new_car = Car(make, model, year, color)
manager.add_car(new_car)
except ValueError:
print("Invalid input. Please enter a valid year.")
except Exception as e:
print(f"Error adding car: {e}")
elif choice == "2":
# Remove a car
make, model = get_car_search_details()
car = manager.find_car(make, model)
if car:
manager.remove_car(car)
else:
print(f"Car {make} {model} not found.")
elif choice == "3":
# List all cars
manager.list_cars()
elif choice == "4":
# Start a car
make, model = get_car_search_details()
car = manager.find_car(make, model)
if car:
car.start()
else:
print(f"Car {make} {model} not found.")
elif choice == "5":
# Stop a car
make, model = get_car_search_details()
car = manager.find_car(make, model)
if car:
car.stop()
else:
print(f"Car {make} {model} not found.")
elif choice == "6":
# Find a car
make, model = get_car_search_details()
car = manager.find_car(make, model)
if car:
print(f"Found: {car} - Running: {car.is_running}")
else:
print(f"Car {make} {model} not found.")
elif choice == "7":
# Exit
print("Thank you for using Car Manager System!")
break
else:
print("Invalid choice. Please enter a number between 1 and 7.")
except KeyboardInterrupt:
print("\n\nExiting Car Manager System...")
break
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
run_car_manager()