car python program

Solutions on MaxInterview for car python program by the best coders in the world

showing results for - "car python program"
Paula
30 Oct 2019
1class Car:
2    def __init__(self, year, make, speed):
3        self.__year_model = year
4        self.__make = make
5        self.__speed = 0
6
7    def set_year_model(self, year):
8        self.__year_model = year
9
10    def set_make(self, make):
11        self.__make = make
12
13    def set_speed(self, speed):
14        self.__speed = 0
15
16    def get_year_model(self):
17        return self.__year_model
18
19    def get_make(self):
20        return self.__make
21
22    def get_speed(self):
23        return self.__speed
24
25    #methods
26    def accelerate(self):
27        self.__speed +=5
28
29    def brake(self):
30        self.__speed -=5
31
32    def get_speed(self):
33        return self.__speed
34
35def main():
36
37    year = input('Enter the car year: ')
38    make = input('Enter the car make: ')
39    speed = 0
40
41    mycar = Car(year, make, speed)
42
43    #Accelerate 5 times
44    mycar.accelerate()
45    print('The current speed is: ', mycar.get_speed())
46    mycar.accelerate()
47    print('The current speed is: ', mycar.get_speed())
48    mycar.accelerate()
49    print('The current speed is: ', mycar.get_speed())
50    mycar.accelerate()
51    print('The current speed is: ', mycar.get_speed())
52    mycar.accelerate()
53    print('The current speed is: ', mycar.get_speed()) 
54
55    #Brake 5 times
56    mycar.brake()
57    print('The current speed after brake is: ', mycar.get_speed())
58    mycar.brake()
59    print('The current speed after brake is: ', mycar.get_speed())
60    mycar.brake()
61    print('The current speed after brake is: ', mycar.get_speed())
62    mycar.brake() 
63    print('The current speed after brake is: ', mycar.get_speed())
64    mycar.brake()
65    print('The current speed after brake is: ', mycar.get_speed())
66
67#Call the main function
68main()