Hi,
After doing the project on python classes, I modified the code which I did in the lesson. In this modified code, the user will be able to give an input and will get the desired result.
The code is mentioned below.
class Car(object):
condition = “new”
def init(self,color,brand,mpg):
self.color = color
self.brand = brand
self.mpg = mpg
def display_car(self):
print(“This is a %s %s of %s MPG” %(self.color, self.brand, self.mpg))
def sec_alternate(self):
self.condition = “used”
class Electric_Car(Car):
def init(self,color,brand,mpg,battery_type):
self.color = color
self.brand = brand
self.mpg = mpg
self.battery_type = battery_type
def display_car(self):
print(“This is a %s %s of %s MPG of the battery type %s.” % (self.color, self.brand, self.mpg,self.battery_type))
def selections():
color = input(“Choose a color:”)
brand = input(“Choose a brand:”)
mpg = input(“Choose the mpg:”)
battery_type = input(“Select the battery_type:”)
my_Car2;Electric_Car(color,brand,mpg,battery_type)
print(my_Car.display_car())
print(selections())
(sorry no intendation, I don’ t know how to do it )
The above code is the modified version of the code in this webpage: https://www.codecademy.com/courses/learn-python/lessons/classes/exercises/overriding-methods?action=resume_content_item .*
I will be very thankful if I get suggestions and feedbacks about this code.
THANK YOU