import csv
import os
FILENAME = "car_modifications.csv"
MODIFICATION_CHOICES = [
"Engine Upgrade",
"Exhaust System",
"Suspension Upgrade",
"Turbocharger/Supercharger",
"Brake Upgrade",
"Custom Paint",
"Alloy Wheels",
"Interior Upgrade",
"Lighting Upgrade",
"Audio System",
]
def get_car_modification_info():
print("\n=== Car Modification Information Form ===")
client_name = input("Client Name: ").strip()
car_make = input("Car Make (e.g., Toyota, BMW): ").strip()
car_model = input("Car Model: ").strip()
while True:
year = input("Year of Manufacture: ").strip()
if year.isdigit() and 1886 <= int(year) <= 2050:
break
print("Invalid year! Enter a valid year between 1886 and 2050.")
# Display modification options
print("\nSelect modifications from the list (type numbers separated by commas):")
for idx, mod in enumerate(MODIFICATION_CHOICES, start=1):
print(f"{idx}. {mod}")
selected_mods = []
choices = input("Your choices: ").split(",")
for choice in choices:
choice = choice.strip()
if choice.isdigit() and 1 <= int(choice) <= len(MODIFICATION_CHOICES):
selected_mods.append(MODIFICATION_CHOICES[int(choice)-1])
client_info = {
"Client Name": client_name,
"Car Make": car_make,
"Car Model": car_model,
"Year": year,
"Modifications": "; ".join(selected_mods)
}
return client_info
def save_to_csv(data):
file_exists = os.path.isfile(FILENAME)
with open(FILENAME, "a", newline="") as csvfile:
fieldnames = ["Client Name", "Car Make", "Car Model", "Year", "Modifications"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
if not file_exists:
writer.writeheader()
writer.writerow(data)
print(f"Data saved for {data['Client Name']}.\n")
def view_records():
if not os.path.isfile(FILENAME):
print("No records found.\n")
return
print("\n=== All Car Modification Records ===")
with open(FILENAME, "r") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(f"{row['Client Name']} | {row['Car Make']} {row['Car Model']} ({row['Year']})")
print(f"Modifications: {row['Modifications']}\n")
def delete_record(client_name):
if not os.path.isfile(FILENAME):
print("No records found.\n")
return
rows = []
deleted = False
with open(FILENAME, "r") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row["Client Name"].lower() != client_name.lower():
rows.append(row)
else:
deleted = True
if deleted:
with open(FILENAME, "w", newline="") as csvfile:
fieldnames = ["Client Name", "Car Make", "Car Model", "Year", "Modifications"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(rows)
print(f"Record for {client_name} deleted.\n")
else:
print(f"No record found for {client_name}.\n")
def main():
while True:
print("=== Car Modification Management ===")
print("1. Add new client info")
print("2. View all records")
print("3. Delete a record by client name")
print("4. Exit")
choice = input("Enter your choice (1-4): ").strip()
if choice == "1":
client_data = get_car_modification_info()
save_to_csv(client_data)
elif choice == "2":
view_records()
elif choice == "3":
name = input("Enter client name to delete: ").strip()
delete_record(name)
elif choice == "4":
print("Exiting program. Goodbye!")
break
else:
print("Invalid choice! Please select 1-4.\n")
if __name__ == "__main__":
main( “)