Created
November 15, 2014 15:34
-
-
Save hcosta/1b2453ab7403d7f398b7 to your computer and use it in GitHub Desktop.
Clase de herencia para youtube
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
# Superclase o clase padre/madre | |
class Libro: | |
# Inicializador | |
def __init__(self, isbn, titulo, autor, precio): | |
# Asignacion de variables | |
self.isbn = isbn | |
self.titulo = titulo | |
self.autor = autor | |
self.precio = precio | |
# Información | |
def info(self): | |
print "\n\n######" | |
print "ISBN:", self.isbn | |
print u"Título:", self.titulo | |
print "Autor:", self.autor | |
print "Precio:", self.precio, "euros" | |
print "######" | |
# Se puede comprar | |
def disponibilidad(self): | |
print self.titulo, u"está disponible" | |
l = Libro('974-3-712-999', 'Don Quijote de la Mancha', | |
'Miguel de Cervantes', 8) | |
l.info() | |
l.disponibilidad() | |
# Clase hija Ebook | |
class Ebook(Libro): | |
def otorgar_enlace(self, enlace): | |
self.enlace = enlace | |
def otorgar_tamano(self, tamano): | |
self.tamano = tamano | |
def info(self): | |
print "\n\n######" | |
print "Tipo: Ebook" | |
print "ISBN:", self.isbn | |
print u"Título:", self.titulo | |
print "Autor:", self.autor | |
print "Precio:", self.precio, "euros" | |
print "Enlace:", self.enlace | |
print u"Tamaño:", self.tamano, "gramos" | |
print "######" | |
e = Ebook('974-3-712-999', 'Don Quijote de la Mancha', | |
'Miguel de Cervantes', 8) | |
e.otorgar_enlace('http://google.com') | |
e.otorgar_tamano(1890) | |
e.info() | |
e.disponibilidad() | |
# Clase hija Papel | |
class Papel(Libro): | |
def otorgar_peso(self, peso): | |
self.peso = peso | |
def otorgar_stock(self, stock): | |
self.stock = stock | |
def disponibilidad(self): | |
if self.stock > 0: | |
print self.titulo, u"sí está disponible" | |
else: | |
print self.titulo, u"no está disponible" | |
def info(self): | |
print "\n\n######" | |
print "Tipo: Papel" | |
print "ISBN:", self.isbn | |
print u"Título:", self.titulo | |
print "Autor:", self.autor | |
print "Precio:", self.precio, "euros" | |
print "Peso:", self.peso, "gramos" | |
print "Stock:", self.stock, "unidades" | |
print "######" | |
lp = Papel('974-3-712-999', 'Don Quijote de la Mancha', | |
'Miguel de Cervantes', 8) | |
lp.otorgar_peso(750) | |
lp.otorgar_stock(0) | |
lp.info() | |
lp.disponibilidad() | |
### LUEGO EJECUTAR ESTO ### | |
lp.otorgar_stock(5) | |
lp.info() | |
lp.disponibilidad() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment