gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Create a class named CarRental that contains fields that hold a renter’s name, zip code,…
- User
Create a class named CarRental that contains fields that hold a renter’s name, zip code, size of the car rented, daily rental fee, length of rental in days, and total rental fee. The class contains a constructor that requires all the rental data except the daily rate and total fee, which are calculated, based on the size of the car: economy at 38.99 per day, or full size at $43.50 per day. The class also includes a display() method that displays all the rental data.
- Assistant
Here's one possible implementation of the CarRental class in Python:
pythonclass CarRental: def __init__(self, name, zip_code, size, days): self.name = name self.zip_code = zip_code self.size = size self.days = days if self.size == 'economy': self.daily_rate = 29.99 elif self.size == 'midsize': self.daily_rate = 38.99 elif self.size == 'full size': self.daily_rate = 43.50 self.total_fee = self.daily_rate * self.days def display(self): print(f"Renter's name: {self.name}") print(f"Zip code: {self.zip_code}") print(f"Size of rented car: {self.size}") print(f"Daily rental fee: ${self.daily_rate}") print(f"Length of rental in days: {self.days}") print(f"Total rental fee: ${self.total_fee}")