Está en la página 1de 4

ALUMNO

class Alumno:
#inicalizamos la clase alumno con sus atributos
""" cuando inica la clase con un valor definido
def __init__(self, nombre, nota):
self.nombre = nombre
self.nota = nota"""
#○cuando inicia solicitando los vaolres de los atributos
def __init__(self):
self.nombre = input("Ingrese nombre del Alumno: ")
self.nota = input("Ingrese nota del alumno: ")

def imprimir(self):
print("alumno: ", self.nombre)
print("nota: ", self.nota)
print("")

def resultado(self):
if int(self.nota) < 11:
print("Alimno Jalado")
elif int(self.nota) >10:
print("Alumno Aprovado")

alumno1 = Alumno()
alumno1.imprimir()
alumno1.resultado()

PILA
class pilas:

#inicializamos las variables


def __init__(self):
self.pila1 = []
self.pila2 = []

def regpila(self):
n=0
lon = int(input("Ingrese la longitud de la pila: "))
for i in range(lon):
n = n+1
l = str(n)
num = input("Ingrese "+l+" numero de la pila: ")
self.pila1.append(num)

def mostarPila(self):
print(self.pila1)

def buscar(self):
unm = 0
nb = input("ingrese numero a buscar: ")
longi = len(self.pila1)
for a in range(longi):
aux = self.pila1.pop()
if aux == nb:
unm = longi
self.pila2.append(aux)
longi = longi-1
print("El numero "+str(nb)+" esta ubicado en la posicion
"+str(unm)+" de la pila.")

pil = pilas()
pil.regpila()
pil.mostarPila()
pil.buscar()
CUADRANTE

import math as mt

class vector2d:

#constructor defino todas las variables a utilizar


def __init__(self, x, y):
self.cx = x
self.cy = y

def modulo(self):
return mt.sqrt(self.cx**2 + self.cy**2)

def getcuadrante(self):
if self.cx >= 0 and self.cy >= 0:
return 1
elif self.cx <= 0 and self.cy >= 0:
return 2
elif self.cx <= 0 and self.cy <= 0:
return 3
else:
return 4

def direccion(self):
cuadrante = self.getcuadrante()
ang = mt.atan(self.cy / self.cx) * 180/mt.pi
if cuadrante == 2 and cuadrante == 3:
ang = 180 + ang
elif cuadrante == 4:
ang = 360 + ang
return ang

def __add__(self, otrovector):


nuevcx = self.cx + otrovector.cx
nuevcy = self.cy + otrovector.cy
return vector2d(nuevcx, nuevcy)

def __str__(self):
return "Vector: " + str(self.cx) + "i + "+str(self.cy) + "j"

v1 = vector2d(4,8)
v2 = vector2d(2,16)
v3 = v1 + v2
print("el resultado es: 1")
print(v3)
print("su modulo es: ",str(v3.modulo()))
print("su direccion es: ",str(v3.direccion()))
print("se encuentra en el cuadrante: ",str(v3.getcuadrante()))
FRACCCION
class fraccion:
#constructor
def __init__(self,num,den):
self.num = num
self.den = den
def __str__(self):
return str(self.num)+"/"+str(self.den)
def __add__(self, otrafraccion):
nvonum =
(self.num*otrafraccion.den+otrafraccion.num*self.den)
nvoden = self.den*otrafraccion.den
return fraccion(nvonum,nvoden)
f1 = fraccion(5,4)
f2 = fraccion(3,5)
f3 = fraccion(8,3)
f4 = fraccion(3,6)

print (f1,f2)
#f1.sumar(f2)
print(f1)
f5 = f3 + f4
print(f5)

MONOMIO
class Monomio:
def __init__(self,num1,var1, num2,var2):
self.num1=num1
self.num2=num2
self.var1=var1
self.var2=var2

def __str__(self):
a=str(self.var1)
b=str(self.var2)
if a == b :
return str(self.num1)+""+str(self.var1)+" +
"+str(self.num2)+""+str(self.var2)+"=
"+str(self.num1+self.num2)+str(self.var2)
else:
return str(self.num1)+""+str(self.var1)+" +
"+str(self.num2)+""+str(self.var2)

a=int(input ("Ingrese 1 numero: "))


v1=str(input ("Ingrese 1 variable: "))
b=int(input ("Ingrese 2 numero: "))
v2=str(input ("Ingrese 2 variable: "))
print(Monomio(a,v1,b,v2))
LISTAS

lst = ["1","4","8","9","0","5"]
print(lst[3:])
print(lst[2:5])

print(lst[:])

lst.append("6")
print(lst[:])

lst.insert(3,"7")
ultimo=lst.pop()

print(lst[:])

eliminado=lst.pop(0)

lst.sort()
lst.reverse()

print(lst[:])
lst.append("8")

pos=lst.index("8")
print(lst[:])
print(pos)

cant=lst.count("8")
print(cant)

También podría gustarte