Output Problem


#1

https://www.codecademy.com/courses/learn-python/lessons/classes/exercises/inheritance-1?action=lesson_resume&link_content_target=interstitial_lesson

I got the tick from the website , however my output is not what i expect it to be, it gives me this output:

new
None
used
<bound method ElectricCar.display_car of <ElectricCar object at 0x7fe7d05890d0>>

I have included my code below, I have tried debugging but apparently I’m just stuck. I hope you guys can help me out! :slight_smile:

class Car(object):
  condition = "new"
  def __init__(self, model, color, mpg):
    self.model = model
    self.color = color
    self.mpg   = mpg
  
  def display_car(self):
  		return  "This is a %s %s with %s MPG." % (self.color, self.model, self.mpg)
   
  def drive_car(self):
    self.condition = "used"
    
 
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
print my_car.drive_car()
print my_car.condition


class ElectricCar(Car):
	def __init__(self , model, color , mpg , battery_type):
  		self.battery_type = battery_type
  		self.model = model
  		self.color = color
  		self.mpg   = mpg
    
my_car = ElectricCar("Honda" , "Red" , 88, "molten salt")
print my_car.display_car


#2

Hi @terasurfer40545,

This statement does not call the display_car method …

print my_car.display_car

The above merely displays a default reference to the identity of the method, which includes a memory location.

Add parentheses after the method name, as follows, to make it into a method call …

print my_car.display_car()

#3

Ah so that was what I missed… Thank you for your help.


#4