solution using IDLE with Python 3.3.1

 

I have the following question that needs a solution using IDLE with Python 3.3.1 i believe. My question appears (page 479 #2) in "Starting out With Python (second edition) Tony Gaddis

Write a class named Car that has the following data attributes:
_ _ year_model (for the car's year model)
_ _ make (for the make of the car)
_ _ speed (for the car's current speed)

The Car class should have an _ _init_ _ method that accept the car's year model and make as arguments. These values should be assigned to the object's _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed data attribute.
The class should also have the following methods:
accelerate
the accelerate method should add 5 to the speed data attribute each time
it is called.
brake
The brake method should subtract 5 from the speed data attribute each time
it is called.
get_speed
The get_speed method should return the current speed.

Next, design a program that creates a Car object, and then calls the accelerate method 5 times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method 5 times. After each call to the brake method, get the current speed of the car and display it.

 

 

 

 

 

    • Posted: 6 years ago
    Solution

    Purchase the answer to view it

    blurred-text
    Save time and money!
    Our teachers already did such homework, use it as a reference!