Python Classes

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

Floors me how this is still not fixed to match the movie, “Back to the Future”. The escape speed was 88 MPH, which would have made this lesson fun and more meaningful. As it stands, all meaning is lost because the connection was never established.

I don’t get what you are saying. It would be better if you give a better a better explanation of it.

Hi @jyotishkaaich,

For advice on formatting posted code so that its indentation is visible, see How to ask good questions (and get good answers).

The semicolon within this line breaks it into two statements:

my_Car2;Electric_Car(color,brand,mpg,battery_type)

Was that line intended as an assignment statement?

DeLorean
The DeLorean

For the context of the car in this Codecademy course, see the video Back To The Future [1985] - The DeLorean.

Thanks to @mtf for bringing this up.

1 Like