Classes lesson 10


#1

Please, I need help with this exercise. I cannot pass it and I don´t know what I´am doing wrong. Maybe I don´t understand properly what they want me to do.

class Auto(object):
	condicion = "nuevo"
	def __init__(self, modelo, color, kpl):
		self.modelo = modelo
		self.color = color
		self.kpl = kpl
	def verAuto(self):
	    return "Este es un " + self.modelo + " " +  self.color + " que alcanza " + str(self.kpl) + " kpl." 
	def manejarAuto(self):
	    self.condicion= "usado"
	   	    
miAuto = Auto("Clio", "gris", 16)
	    
class AutoElectrico(Auto):
    def __init__(self, modelo, color, kpl, tipoDeBateria):
        Auto.__init__(self, modelo, color, kpl)
        self.tipoDeBateria = tipoDeBateria
    def manejarAuto(self):
        self.condicion="como nuevo"
             
print miAuto.condicion
miAuto.manejarAuto()
print miAuto.condicion
        
miAuto = AutoElectrico("Toyota", "rojo", 142, "sales fundidas")

#2

When you are running

print miAuto.condicion
miAuto.manejarAuto()
print miAuto.condicion

miAuto is set to Auto("Clio", "gris", 16)

and then after everything has been ran you set miAuto to AutoElectrico("Toyota", "rojo", 142, "sales fundidas")

For the AutoElectrico method to override the parent method, you need to have miAuto = AutoElectrico("Toyota", "rojo", 142, "sales fundidas")
before your print statements.


#3

Thank you very much. Everything is all right now


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.