0% found this document useful (0 votes)
22 views4 pages

Car Rental Management System Code

This document outlines a professional car rental system implemented in Python, utilizing pandas for data management and matplotlib for reporting. It allows users to add, edit, delete, and view customer records, as well as generate daily and monthly collection reports based on car type. The system reads from and writes to a CSV file for data persistence.

Uploaded by

Divyanshu Shukla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Car Rental Management System Code

This document outlines a professional car rental system implemented in Python, utilizing pandas for data management and matplotlib for reporting. It allows users to add, edit, delete, and view customer records, as well as generate daily and monthly collection reports based on car type. The system reads from and writes to a CSV file for data persistence.

Uploaded by

Divyanshu Shukla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import pandas as pd

import [Link] as plt


from datetime import datetime
import os

# Constants
FILE_NAME = 'car_rental.csv'
HEADERS = ['Serial No', 'Person Name', 'Check-In', 'Check-Out', 'Car Type', 'Billing Amount', 'ID Card']

# Load or initialize CSV


if [Link](FILE_NAME):
df = pd.read_csv(FILE_NAME)
else:
df = [Link](columns=HEADERS)
df.to_csv(FILE_NAME, index=False)

while True:
print("\n" + "=" * 60)
print(" PROFESSIONAL CAR RENTAL SYSTEM".center(60))
print("=" * 60)
print("1 Add New Customer")
print("2 Edit Customer Detail")
print("3 Delete Customer")
print("4 View One Customer")
print("5 View All Customers")
print("6 Daily Collection Report (Car Type-wise)")
print("7 Monthly Collection Report (Car Type-wise)")
print("8 Exit")
print("=" * 60)

choice = input("Enter your choice (1-8): ").strip()

if choice == '1':
print("\n Add New Customer")
name = input("Full Name: ").strip().title()
try:
check_in = input("Check-In (YYYY-MM-DD HH:MM): ")
check_in_dt = [Link](check_in, "%Y-%m-%d %H:%M")
except:
print(" Invalid date format.")
continue
try:
check_out = input("Check-Out (YYYY-MM-DD HH:MM): ")
check_out_dt = [Link](check_out, "%Y-%m-%d %H:%M")
except:
print(" Invalid date format.")
continue

car_type = input("Car Type (AC / Non-AC): ").strip().upper()


if car_type not in ['AC', 'NON-AC']:
print(" Invalid Car Type.")
continue
try:
billing = float(input("Billing Amount: ").strip())
except:
print(" Invalid billing amount.")
continue

id_card = input("ID Card Number: ").strip()

serial = 1 if [Link] else df['Serial No'].max() + 1

new_row = {
'Serial No': serial,
'Person Name': name,
'Check-In': check_in_dt.strftime("%Y-%m-%d %H:%M"),
'Check-Out': check_out_dt.strftime("%Y-%m-%d %H:%M"),
'Car Type': car_type,
'Billing Amount': billing,
'ID Card': id_card
}

df = [Link]([df, [Link]([new_row])], ignore_index=True)


df.to_csv(FILE_NAME, index=False)
print(" Customer added successfully.")

elif choice == '2':


print("\n Edit Customer Details")
try:
serial = int(input("Enter Serial Number: "))
except:
print(" Invalid serial number.")
continue

if serial not in df['Serial No'].values:


print(" Serial number not found.")
continue

idx = df[df['Serial No'] == serial].index[0]


print("Leave field empty to keep current value.")

name = input(f"Name [{[Link][idx, 'Person Name']}]: ") or [Link][idx, 'Person Name']


check_in = input(f"Check-In [{[Link][idx, 'Check-In']}]: ") or [Link][idx, 'Check-In']
check_out = input(f"Check-Out [{[Link][idx, 'Check-Out']}]: ") or [Link][idx, 'Check-Out']
car_type = input(f"Car Type [{[Link][idx, 'Car Type']}]: ") or [Link][idx, 'Car Type']
billing = input(f"Billing Amount [{[Link][idx, 'Billing Amount']}]: ") or [Link][idx, 'Billing Amount']
id_card = input(f"ID Card [{[Link][idx, 'ID Card']}]: ") or [Link][idx, 'ID Card']

try:
[Link][idx, 'Person Name'] = [Link]().title()
[Link][idx, 'Check-In'] = [Link](check_in, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %H:%M")
[Link][idx, 'Check-Out'] = [Link](check_out, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %H:%M")
[Link][idx, 'Car Type'] = car_type.strip().upper()
[Link][idx, 'Billing Amount'] = float(billing)
[Link][idx, 'ID Card'] = id_card.strip()
except:
print(" Error in updating values. Check your inputs.")
continue

df.to_csv(FILE_NAME, index=False)
print(" Customer details updated.")

elif choice == '3':


print("\n Delete Customer")
try:
serial = int(input("Enter Serial Number to Delete: "))
except:
print(" Invalid input.")
continue

if serial in df['Serial No'].values:


df = df[df['Serial No'] != serial]
df.to_csv(FILE_NAME, index=False)
print(" Customer deleted.")
else:
print(" Serial number not found.")

elif choice == '4':


print("\n View One Customer")
try:
serial = int(input("Enter Serial Number: "))
except:
print(" Invalid input.")
continue

result = df[df['Serial No'] == serial]


if [Link]:
print(" Customer not found.")
else:
print(result.to_string(index=False))

elif choice == '5':


print("\n All Customer Records")
if [Link]:
print(" No data found.")
else:
print(df.to_string(index=False))

elif choice == '6':


print("\n Daily Collection Report")
if [Link]:
print(" No data available.")
continue

df['Check-In Date'] = pd.to_datetime(df['Check-In']).[Link]


daily_report = [Link](['Check-In Date', 'Car Type'])['Billing Amount'].sum().unstack().fillna(0)
print(daily_report)

daily_report.plot(kind='bar', stacked=True, figsize=(10,5), title="Daily Collection by Car Type")


[Link]("Amount (Rs.)")
[Link]("Date")
plt.tight_layout()
[Link]()

elif choice == '7':


print("\n Monthly Collection Report")
if [Link]:
print(" No data available.")
continue

df['Month'] = pd.to_datetime(df['Check-In']).dt.to_period('M')
monthly_report = [Link](['Month', 'Car Type'])['Billing Amount'].sum().unstack().fillna(0)
print(monthly_report)

monthly_report.plot(kind='line', marker='o', figsize=(10,5), title="Monthly Collection by Car Type")


[Link]("Amount (Rs.)")
[Link]("Month")
plt.tight_layout()
[Link]()

elif choice == '8':


print("\n Thank you for using the Car Rental System. Goodbye!")
break

else:
print(" Invalid choice. Please enter a number between 18.")

You might also like