Untitled
unknown
plain_text
a month ago
975 B
1
Indexable
```python class Car: def __init__(self, make, model, year): self.make = make self.model = model self.year = year self.odometer_reading = 0 def get_descriptive_name(self): long_name = f"{self.year} {self.make} {self.model}" return long_name.title() def read_odometer(self): print(f"This car has {self.odometer_reading} miles on it.") def update_odometer(self, mileage): if mileage >= self.odometer_reading: self.odometer_reading = mileage else: print("You can't roll back an odometer!") def increment_odometer(self, miles): self.odometer_reading += miles # Create an instance of Car my_car = Car('Audi', 'A4', 2020) # Display car details print(my_car.get_descriptive_name()) # Update and read odometer my_car.update_odometer(10000) my_car.read_odometer() # Increment odometer and read again my_car.increment_odometer(500) my_car.read_odometer()
Editor is loading...
Leave a Comment