Lab 13 OOP
Lab 13 OOP
| Introduction to Programming |
| Ali Dumlu |
| Email: [email protected] |
--------------------------------------------
Start by defining the class using the class keyword followed by the
class name Car. Inside the class, define the __init__ method to
initialize the object's attributes.
class Car:
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0
def get_description(self):
Outside of the class create two instances of the class and demonstrate
how to use the methods to access and modify the private attribute.
print(car1.get_description())
print(car2.get_description())
car1.odometer_reading += 100
car2.odometer_reading -= 250
self.__odometer_reading = 0
def read_odometer(self):
def get_description(self):
Update the test program to make use of the changes which has been made.
print(car1.get_description())
print(car2.get_description())
print(f"car1.read_odometer()}")
print(f"car2.read_odometer()}")
car1.increase_odometer(100)
car2.increase_odometer(250)
print(car1.read_odometer())
print(car2.read_odometer())
Questions
The following output illustrates what the result of running this test
application might look like:
----------------------------------------------------------------