Programming Exercise 3-1
Programming Exercise 10-2
# car.py
class Car:
def __init__(self, year_model, make):
self.__year_model = year_model;
self.__make = make
self.__speed = 0
def accelerate(self):
self.__speed += 5
def brake(self):
self.__speed -=5
def get_speed(self):
return self.__speed
# Exercise 10-2.py
import car
def main():
# Create an instance of Car.
my_car = car.Car(‘2008’, ‘Honda Accord’)
# Accelerate 5 times.
print(‘car is accelerating: ‘)
for i in range(5):
my_car.accelerate()
print (‘Current speed: ‘, my_car.get_speed())
print()
# Brake 5 times.
print (‘car is braking: ‘)
for i in range(5):
my_car.brake()
print (‘Current speed: ‘, my_car.get_speed())
# Call the main function.
main()