Question: Can someone tell me what I'm doing wrong: This is the question I'm answering: N PYTHON: Write a class named Car that has the following

Can someone tell me what I'm doing wrong:

This is the question I'm answering:

N PYTHON:

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 accepts the car'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 five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method five times. After each call to the brake method, get the current speed of the car and display it.

This is my code:

# Create a class Car and initlize year_model and make class Car: def __int__(self, year_model, make): self.__year_model = year_model self.__make = make self.__speed = 0

# Accelerate method exceded the speed by 5 def accelearte(self): self.__speed += 5

# Break method decreases teh value by 5 def brake(self): self.__speed -= 5

# get_speed accessor(getter) method returns current speed def get_speed(self): return self.__speed # Create main function def main(): # Ask the user for the car year and model car_year = int(input('Enter the year of the car: ')) car_make = input('Enter the make of the car: ') car1 = Car(car_year, car_make)

# Call accelerate method car1.accelerate() print('The current speed of the car is: ', car1.get_speed, car1.accelerate) print('The current speed of the car is: ', car1.get_speed, car1.accelerate) print('The current speed of the car is: ', car1.get_speed, car1.accelerate) print('The current speed of the car is: ', car1.get_speed, car1.accelerate) print('The current speed of the car is: ', car1.get_speed, car1.accelerate) print() # Call break method print('The current speed of the car is: ', car1.get_speed, car1.brake) main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!