You are designing a feature for the Vehicle Rental System that allows customers to calculate the total rental charge for a specific vehicle. The system provides a list of available vehicles, where each vehicle is represented by a tuple containing the vehicle's name, model, rental status, and price per day. The customer will select the vehicle by specifying the name and model, and then input the number of days they wish to rent the vehicle. Define a method calculate_rental_charge in the Vehicle_Rental_System class to calculate the rent for the vehicle for the given days and return the valueIf the vehicle is not available or vehicle model is not available then return -1Constraints:Input Format:The first line of input is name of the vehicleThe second line of input is model of the vehicleThe third line of input is no of days the customer want to take rentOutput Format:Single line of input displays charge for the no of days if not display -1Example:Sample Input 1:ToyotaCamry5Sample Output 1:250Explanation:Explanation:Toyota vehicle of Camry model is availableNo of days is 5 Charge is 5*50So, the output will be 250
Question
You are designing a feature for the Vehicle Rental System that allows customers to calculate the total rental charge for a specific vehicle. The system provides a list of available vehicles, where each vehicle is represented by a tuple containing the vehicle's name, model, rental status, and price per day. The customer will select the vehicle by specifying the name and model, and then input the number of days they wish to rent the vehicle. Define a method calculate_rental_charge in the Vehicle_Rental_System class to calculate the rent for the vehicle for the given days and return the valueIf the vehicle is not available or vehicle model is not available then return -1Constraints:Input Format:The first line of input is name of the vehicleThe second line of input is model of the vehicleThe third line of input is no of days the customer want to take rentOutput Format:Single line of input displays charge for the no of days if not display -1Example:Sample Input 1:ToyotaCamry5Sample Output 1:250Explanation:Explanation:Toyota vehicle of Camry model is availableNo of days is 5 Charge is 5*50So, the output will be 250
Solution 1
To solve this problem, we need to create a class named Vehicle_Rental_System and define a method calculate_rental_charge in it. This method will take three parameters: vehicle_name, vehicle_model, and rent_days.
Here is the Python code for the problem:
class Vehicle_Rental_System:
def __init__(self):
# List of available vehicles
# Each vehicle is represented by a tuple (name, model, rental status, price per day)
self.vehicles = [('Toyota', 'Camry', True, 50), ('Honda', 'Civic', True, 60), ('Ford', 'Mustang', False, 100)]
def calculate_rental_charge(self, vehicle_name, vehicle_model, rent_days):
# Iterate over the list of vehicles
for vehicle in self.vehicles:
# Check if the vehicle name and model match the input and if the vehicle is available for rent
if vehicle[0] == vehicle_name and vehicle[1] == vehicle_model and vehicle[2] == True:
# Calculate the total rental charge
total_charge = vehicle[3] * rent_days
return total_charge
# If the vehicle is not available or the model is not available, return -1
return -1
You can use the calculate_rental_charge method like this:
rental_system = Vehicle_Rental_System()
print(rental_system.calculate_rental_charge('Toyota', 'Camry', 5)) # Output: 250
This code will return the total rental charge for the specified vehicle and number of days. If the vehicle or model is not available, it will return -1.
Solution 2
To solve this problem, we need to create a class named Vehicle_Rental_System and define a method calculate_rental_charge in it. This method will take three parameters: vehicle_name, vehicle_model, and rent_days.
Here is the Python code for the problem:
class Vehicle_Rental_System:
def __init__(self):
self.vehicles = [('Toyota', 'Camry', True, 50), ('Honda', 'Civic', True, 60), ('Ford', 'Mustang', False, 70)]
def calculate_rental_charge(self, vehicle_name, vehicle_model, rent_days):
for vehicle in self.vehicles:
if vehicle[0] == vehicle_name and vehicle[1] == vehicle_model and vehicle[2] == True:
return vehicle[3] * rent_days
return -1
In the __init__ method, we initialize a list of tuples where each tuple represents a vehicle. Each tuple contains the vehicle's name, model, rental status, and price per day.
In the calculate_rental_charge method, we iterate over the list of vehicles. If we find a vehicle with the given name and model and its rental status is True, we calculate the total rental charge by multiplying the price per day by the number of rent days and return this value. If we don't find such a vehicle, we return -1.
You can use this class and method like this:
rental_system = Vehicle_Rental_System()
print(rental_system.calculate_rental_charge('Toyota', 'Camry', 5)) # Output: 250
This will print 250 because the Toyota Camry is available for rent and its price per day is 50. So, the total rental charge for 5 days is 50 * 5 = 250.
Similar Questions
Linda has 24 cars available to rent.Let C be the number of cars she would have left after renting R of them.Write an equation relating C to R. Then use this equation to find the number of cars she would have left after renting 8 of them.
Problem StatementJohn, a software developer in a new city, is seeking your assistance to create a call-by-value function that calculates parking charges for his car trips. The program takes user inputs for the parking spot type ('c' for compact, 'b' for basic, 't' for premium) and total parking time in hours. It then calculates and displays the total parking charge based on predefined rates for each spot type (2 times for compact, 3 times for basic, and 4 times for premium).Function Specifications: float parkingCharge(char s, float parkingtime)Input format :The first line of input consists of a character, representing the type of parking spot ('c' for compact, 'b' for basic, and 't' for premium).The second line consists of a floating-point value, representing the total parking time in hours.Output format :The output displays a floating-point value, representing the total parking charge, rounded off to two decimal places.Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:Parking spot - 'c' for compact, 'b' for basic, and 't' for premium1.00 ≤ parking time ≤ 500.00Sample test cases :Input 1 :c1.75Output 1 :3.50Input 2 :b10.25Output 2 :30.75Input 3 :t475.50Output 3 :1902.00
The cost, in dollars, of a one-day car rental is given by C(x) = 31 + 0.18x, where x is the number of miles driven. In this function,
Problem 2: Classes and Objects Scenario: Write a Python program to implement the concept of classes, methods, and objects. Instructions: Create a Python Class named “Vehicle.” This Class will have a total of five (5) attributes and one (1) method, as follows: o Attributes: type, total_seats, color, price, mileage o Method: print_detail() If the total number of seats in a vehicle is more than seven (7) and the price is more than $50,000, print “It is an unaffordable vehicle.” Otherwise, print “You may afford and easily park it.” Create the following four (4) vehicle objects: bus, bike, car, and pickup_truck. For each object, take the attribute value from the user. This means the user will enter all five (5) attribute values for each object. Assign these values to the related object and print all the details one by one. In your program logic, you must use the concept of classes, methods, and objects, as well as accessing methods through objects. Save your Python file as: Problem2_StudentNameInitials
Create a class called “HotelRoom” that includes an integer field for the room number and a double field for the nightly rental rate. Include get methods for these fields and a constructor that requires an integer argument representing the room number. The constructor sets the room rate based on the room number; rooms numbered 100 and below are Rs 500 per night, others are Rs.800 per night.Create an extended class name Suite whose constructor requires a room number and adds a Rs 400 surcharge to the regular hotel room rate based on the room number. Write a program to demonstrate creating and using an object of each class.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.