Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.1 kB
1
Indexable
Never
class Circulo(object):
    r = 0 #Atributo radio
    pi = 3.1416
    def _init_(self,r): #cuando ponemos self es que es un atributo de la clas 
        self.r = r
        
    def Diametro(self):
        return self.r*2
    
    def Area(self):
        return self.pi*self.r**2
    
    def Perimetro(self):
        return 2*self.pi*self.r
    
    def DaRadio(self):
        print('El valor del radio es: ',self.r)
        
        def Imprimirvalores(self):
            print('Radio: ',self.r)
            print('Diametro: ', self.Diametro())
            print('Perimetro: ', self.Perimetro())
            print('Area: ', self.Area())
    
lista = [Circulo(10), Circulo(7), Circulo(45), 'texto']

for c in lista:  
    if issubclass(type(c),Circulo): 
        c = Circulo(5)
        c.DaRadio()
        print(c.Diametro())
        print(c.Area())
        print(c.Perimetro)
    else:
        print('El elemento no es de la clase Circulo')
        
        
for i in range(2,11,2):
    c = Circulo(i)
    print(c.Diametro())
    print(c.Area())
    print(c.Perimetro())