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

Python Project

Uploaded by

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

Python Project

Uploaded by

Madan Kumar R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

from datetime import datetime

# Rental rules
vehicle_rules = {
'small_car': {'rate': 30, 'min_age': 17, 'license': 'full',
'early_discount': 1.0, 'late_fee': 0.2, 'ac_extra': 0.1},
'family_car': {'rate': 40, 'min_age': 21, 'license': 'full',
'early_discount': 0.5, 'late_fee': 0.2, 'ac_extra': 0.1},
'luxury_car': {'rate': 150,'min_age': 25, 'license': 'full',
'early_discount': 0.3, 'late_fee': 0.3, 'ac_extra': 0.0},
'small_van': {'rate': 50, 'min_age': 21, 'license': 'full',
'early_discount': 0.5, 'late_fee': 0.2, 'ac_extra': 0.1},
'large_van': {'rate': 70, 'min_age': 25, 'license':
'heavy','early_discount': 0.5, 'late_fee': 0.2, 'ac_extra': 0.1}
}

# Driver class
class Driver:
def __init__(self, name, age, license_type):
self.name = name
self.age = age
self.license_type = license_type

# Vehicle class
class Vehicle:
def __init__(self, make, category, has_ac):
self.make = make
self.category = category
self.has_ac = has_ac
self.driver = None
self.start_date = None
self.end_date = None

def is_driver_eligible(self, driver):


rule = vehicle_rules[self.category]
return driver.age >= rule['min_age'] and driver.license_type ==
rule['license']

def rent(self, driver, start_date, end_date):


self.driver = driver
self.start_date = start_date
self.end_date = end_date
print(f"\n✅ {self.make} rented successfully to {driver.name}")

def return_vehicle(self, return_date):


rule = vehicle_rules[self.category]
base_rate = rule['rate']
if self.has_ac:
base_rate += base_rate * rule['ac_extra']
total_days = (self.end_date - self.start_date).days + 1
used_days = (return_date - self.start_date).days + 1

if return_date < self.end_date:


unused_days = (self.end_date - return_date).days
discount = unused_days * base_rate * rule['early_discount']
total_cost = used_days * base_rate - discount
elif return_date > self.end_date:
extra_days = (return_date - self.end_date).days
extra_fee = extra_days * base_rate * rule['late_fee']
total_cost = total_days * base_rate + extra_fee
else:
total_cost = total_days * base_rate

print(f"\n💰 Total charge: £{round(total_cost, 2)}")

# List of available vehicles


available_vehicles = [
Vehicle("Toyota Yaris", "small_car", True),
Vehicle("Honda City", "family_car", False),
Vehicle("BMW 5 Series", "luxury_car", True),
Vehicle("Suzuki Van", "small_van", True),
Vehicle("Tata Ace", "large_van", False),
]

# Main program loop


def start_rental_process():
while True:
print("\n📦 Welcome to the Vehicle Rental System")

try:
# Driver input
name = input("Enter driver's name: ")
age = int(input("Enter driver's age: "))
license_type = input("Enter license type (full/heavy/provisional):
").strip().lower()
driver = Driver(name, age, license_type)

# Filter eligible vehicles


eligible = [v for v in available_vehicles if
v.is_driver_eligible(driver)]
if not eligible:
print("❌ No vehicles available for your age and license type.
Please try again.\n")
continue

print("\n🚗 Eligible Vehicles:")


for idx, v in enumerate(eligible):
ac_status = "Yes" if v.has_ac else "No"
print(f"{idx + 1}. {v.make} | {v.category} | AC: {ac_status}")

# Selection
choice = int(input("Select a vehicle by number: ")) - 1
selected_vehicle = eligible[choice]

# Dates
start_str = input("Enter rental start date (YYYY-MM-DD): ")
end_str = input("Enter rental end date (YYYY-MM-DD): ")
start_date = datetime.strptime(start_str, "%Y-%m-%d")
end_date = datetime.strptime(end_str, "%Y-%m-%d")

# Rent vehicle
selected_vehicle.rent(driver, start_date, end_date)

# Return and calculate


return_str = input("Enter actual return date (YYYY-MM-DD): ")
return_date = datetime.strptime(return_str, "%Y-%m-%d")
selected_vehicle.return_vehicle(return_date)
break # End loop after successful transaction

except Exception as e:
print(f"\n⚠️ Error: {e}")
print("🔁 Restarting the process...\n")

# Run the program


if __name__ == "__main__":
start_rental_process()

You might also like