0% found this document useful (0 votes)
43 views14 pages

CS Practical by Rudra

The document outlines a menu-driven Python program for managing a car showroom using dictionaries. It allows users to add, view, update, and delete car entries based on a unique Car ID. The program runs in a loop until the user chooses to exit, providing feedback on each action taken.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views14 pages

CS Practical by Rudra

The document outlines a menu-driven Python program for managing a car showroom using dictionaries. It allows users to add, view, update, and delete car entries based on a unique Car ID. The program runs in a loop until the user chooses to exit, providing feedback on each action taken.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q- Write a menu

driven Python
Program on Car
Showroom
Management using
Dictionaries.
# Car Showroom Management
System

cars = {}

while True:
print("\nCar Showroom
Management System")
print("1. Add Car")
print("2. View Cars")
print("3. Update Car")
print("4. Delete Car")
print("5. Exit")

choice = input("Enter your


choice: ")

if choice == '1':
car_id = input("Enter Car ID: ")
if car_id in cars:
print("Car ID already exists.
Please use a unique ID.")
continue
brand = input("Enter Car
Brand: ")
model = input("Enter Car
Model: ")
year = input("Enter Car Year:
")
price = input("Enter Car Price:
")
cars[car_id] = {
'brand': brand,
'model': model,
'year': year,
'price': price
}
print("Car added
successfully!")

elif choice == '2':


if not cars:
print("No cars available.")
else:
print("\nAvailable Cars:")
for car_id, details in
cars.items():
print(f"ID: {car_id},
Brand: {details['brand']}, Model:
{details['model']}, Year:
{details['year']}, Price:
{details['price']}")

elif choice == '3':


car_id = input("Enter Car ID to
update: ")
if car_id not in cars:
print("Car ID not found.")
continue
brand = input("Enter new Car
Brand (leave blank to keep
current): ")
model = input("Enter new Car
Model (leave blank to keep
current): ")
year = input("Enter new Car
Year (leave blank to keep current):
")
price = input("Enter new Car
Price (leave blank to keep current):
")

if brand:
cars[car_id]['brand'] = brand
if model:
cars[car_id]['model'] =
model
if year:
cars[car_id]['year'] = year
if price:
cars[car_id]['price'] = price

print("Car updated
successfully!")
elif choice == '4':
car_id = input("Enter Car ID to
delete: ")
if car_id in cars:
del cars[car_id]
print("Car deleted
successfully!")
else:
print("Car ID not found.")

elif choice == '5':


print("Exiting the program.
Goodbye!")
break

else:
print("Invalid choice. Please
try again.")
RESULT

Car Showroom Management System


1. Add Car
2. View Cars
3. Update Car
4. Delete Car
5. Exit
Enter your choice: 1
Enter Car ID: cp23
Enter Car Brand: porsche
Enter Car Model: 911
Enter Car Year: 2020
Enter Car Price: 500000
Car added successfully!

Car Showroom Management System


1. Add Car
2. View Cars
3. Update Car
4. Delete Car
5. Exit
Enter your choice: 1
Enter Car ID: cp123
Enter Car Brand: mustang
Enter Car Model: shelby gt500
Enter Car Year: 2022
Enter Car Price: 90000
Car added successfully!

Car Showroom Management System


1. Add Car
2. View Cars
3. Update Car
4. Delete Car
5. Exit
Enter your choice: 1
Enter Car ID: cp455
Enter Car Brand: ferrari
Enter Car Model: f8 tributo
Enter Car Year: 2019
Enter Car Price: 800000
Car added successfully!
Car Showroom Management System
1. Add Car
2. View Cars
3. Update Car
4. Delete Car
5. Exit
Enter your choice: 2

Available Cars:
ID: cp23, Brand: porsche, Model:
911, Year: 2020, Price: 500000
ID: cp123, Brand: mustang, Model:
shelby gt500, Year: 2022, Price:
90000
ID: cp455, Brand: ferrari, Model: f8
tributo, Year: 2019, Price: 800000

Car Showroom Management System


1. Add Car
2. View Cars
3. Update Car
4. Delete Car
5. Exit
Enter your choice: 5
Exiting the program. Goodbye!

You might also like