class Vehiculo(): def __init__(self, color, ruedas): self.color = color self.ruedas = ruedas print("\n El vehículo se ha creado con éxito!") def __str__(self): info = "Color: " + self.color + "\n Ruedas: " + str(self.rueadas) return info class Coche (Vehiculo): def __init__(self, color, ruedas, velocidad, cilindrada): self.velocidad = velocidad self.cilindrada = cilindrada super().__init__(color, ruedas) def __str__ (self): info = "\n Coche \n Color: " + self.color + "\n Ruedas: " + str(self.ruedas) + "\n Velocidad: " + str(self.velocidad) + "\n Cilindrada: " + str(self.cilindrada) return info coche1 = Coche("Rojo", 4, 200, 500) print(coche1) coche2 = Coche("Blanco", 4, 170, 450) print(coche2) coche3 = Coche("Negro", 4, 250, 650) print(coche3)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter