THADOMAL SHAHANI ENGINEERING COLLEGE
DEPARTMENT OF INFORMATION TECHNOLOGY
Assignment 1: Vehicle Rental System
Aim: To develop a vehicle rental system.
Theory:
The below code is developed for VEHICLE RENTAL SYSTEM that is allowing users to rent a
car or bus. It also asks users for the number of days they want to rent a particular vehicles and also
the number of vehicles they want to rent. It also provides the total amount that is to be paid to the
individual.
This experiment demonstrates a rental system for cars and buses using Python. The system allows
users to check available vehicles, rent them for a specific number of days, and calculates the total
rental cost. The program is implemented using Object-Oriented Programming (OOP) concepts
such as classes, inheritance, and methods.
1. Classes and Objects
The program defines three classes:
• Vehicle – Stores the number of available cars and buses.
• Rental_Agency – Provides rental details like rent per day.
• Rental_Transaction – Manages bookings and calculates the total rental cost.
An object of Rental_Transaction is used to interact with the user.
2. Inheritance
• Rental_Agency inherits from Vehicle, and Rental_Transaction inherits from
Rental_Agency.
• This allows child classes to access and extend the features of their parent classes.
3. Handling User Input
• The program takes user input using input(), such as selecting a vehicle, entering the number
of vehicles, and specifying rental days.
DIVYA PATIL (146)
• The input is converted to integers using int().
4. Control Flow
• A while loop keeps the program running until the user decides to exit.
• if-elif-else conditions handle user choices and booking validation.
5. Rental Cost Calculation
• The total rent is calculated using a simple formula:
Total Cost=Number of Vehicles×Days×Rate per Day\text{Total Cost} = \text{Number of
Vehicles} \times \text{Days} \times \text{Rate per Day}Total Cost=Number of
Vehicles×Days×Rate per Day
• Cars are rented at ₹25 per day, and buses at ₹50 per day.
6. Output Display
The program uses print() to show:
• Available vehicles
• Rental prices
• Confirmation messages for successful bookings
• Error messages for invalid choices
Program with output:
class Vehicle:
def __init__(self, cars, bus):
[Link] = cars
[Link] = bus
def vehicles_available(self):
print(f"Available cars: {[Link]}")
print(f"Available buses: {[Link]}")
DIVYA PATIL (146)
class Rental_Agency(Vehicle):
def __init__(self, cars, bus):
super().__init__(cars, bus)
def rental_period(self, days):
[Link] = days
print(f"Rental period is {[Link]} days")
def display_car_rent(self):
print(f"The available cars are {[Link]} with a rent of 25 Rs per day at Star Agency.")
def display_bus_rent(self):
print(f"The available buses are {[Link]} with a rent of 50 Rs per day at Royal Agency.")
class Rental_Transaction(Rental_Agency):
def __init__(self, cars, bus):
super().__init__(cars, bus)
def customer_booking(self, num_of_vehicles, days, vehicle_type):
rent_price = 0
if vehicle_type == 1:
rent_price = num_of_vehicles * days * 25
print(f"Your order for {num_of_vehicles} cars at Star Agency is booked. Please pay Rs
{rent_price}.")
elif vehicle_type == 2:
DIVYA PATIL (146)
rent_price = num_of_vehicles * days * 50
print(f"Your order for {num_of_vehicles} buses at Royal Agency is booked. Please pay
Rs {rent_price}.")
else:
print("Invalid vehicle type selected.")
if __name__ == "__main__":
rental_agency = Rental_Transaction(cars=200, bus=100)
while True:
print("\n1. For renting car")
print("2. For renting bus")
print("3. For exit")
choice = int(input("Enter your choice: "))
if choice == 1:
rental_agency.display_car_rent()
num_of_cars = int(input("Enter number of cars you want to rent: "))
days = int(input("Enter the number of days you want to rent: "))
rental_agency.customer_booking(num_of_cars, days, 1)
elif choice == 2:
rental_agency.display_bus_rent()
DIVYA PATIL (146)
num_of_buses = int(input("Enter number of buses you want to rent: "))
days = int(input("Enter the number of days you want to rent: "))
rental_agency.customer_booking(num_of_buses, days, 2)
elif choice == 3:
print("Exiting")
break
else:
print("Invalid choice. Please try again.")
Conclusion:
Hence, we successfully developed a VEHICLE RENTAL SYSTEM. We applied Object-
Oriented Programming (OOP) concepts such as classes, inheritance, and methods to manage
vehicle availability, rental pricing, and customer bookings. The program used user input
handling, loops, and conditional statements to create an interactive rental system. Through this,
we learned how to design a structured program that calculates rental costs and processes user
bookings efficiently.
DIVYA PATIL (146)
DIVYA PATIL (146)