diff --git a/clase_2/9_variablesGlobalesLocales.py b/clase_2/9_variablesGlobalesLocales.py index d197412..854b65b 100644 --- a/clase_2/9_variablesGlobalesLocales.py +++ b/clase_2/9_variablesGlobalesLocales.py @@ -2,10 +2,53 @@ contador = 0 print(f"el contador es: {contador}") def verContador(): - contador=0 + global contador contador += 1 print(f"el contador dentro de la f es : {contador}") verContador() -print(f"el contador es: {contador}") \ No newline at end of file +print(f"el contador es: {contador}") + +triple = lambda x: x * x * 3 + +print(triple(2)) + + +edad = 17 + +def verificar(): + if edad >= 18: + print("Mayor") + else: + print("Menor") + +verificar() + +print(type(3.14)) + + +productos = [ + { + "nombre": "Notebook", + "marca": "Lenovo", + "precio": 850000 + }, + { + "nombre": "Monitor", + "marca": "Samsung", + "precio": 250000 + }, + { + "nombre": "Teclado", + "marca": "Logitech", + "precio": 45000 + } +] + + +contador = 5 + +while contador > 0: + print(contador) + contador -= 1 \ No newline at end of file diff --git a/clase_2/3_ejercicio_de_funciones.py b/clase_2/ejercicio_de_funciones.py similarity index 100% rename from clase_2/3_ejercicio_de_funciones.py rename to clase_2/ejercicio_de_funciones.py diff --git a/clase_3/ejercicio_3.py b/clase_3/ejercicio_3.py index d532369..3b71fb4 100644 --- a/clase_3/ejercicio_3.py +++ b/clase_3/ejercicio_3.py @@ -36,6 +36,7 @@ peliculas=[ } ] +print(f"el genero es {peliculas[0]["Genero"]}") for peli in peliculas: print(f"-----------------------Género: {peli["Genero"]}--------------------") for gen in peli["Pelicula"]: diff --git a/clase_4/excepciones.png b/clase_4/excepciones.png new file mode 100644 index 0000000..6aa054e Binary files /dev/null and b/clase_4/excepciones.png differ diff --git a/clase_4/excepciones.py b/clase_4/excepciones.py new file mode 100644 index 0000000..6b6c495 --- /dev/null +++ b/clase_4/excepciones.py @@ -0,0 +1,70 @@ +print("=== MANEJO DE EXCEPCIONES ===") + +try: + numero1 = int(input("Ingrese el primer número: ")) + numero2 = int(input("Ingrese el segundo número: ")) + + resultado = numero1 / numero2 + +except ValueError: + + print("Error: Debe ingresar únicamente números enteros.") + +except ZeroDivisionError: + + print("Error: No es posible dividir por cero.") + +else: + + print(f"La división es: {resultado}") + +finally: + + print("Fin del programa.") + +############################################################33 + +try: + # Lista con tres elementos + alumnos = ["Juan", "Pedro", "María"] + + # El índice 5 no existe + print(alumnos[5]) + +except IndexError: + print("Error: El índice indicado no existe en la lista.") + +else: + print("La lista se recorrió correctamente.") + +finally: + print("Fin del programa.") + + + +##################excepciones personalizadas######################## + +class EdadInvalida(Exception): + pass + + +try: + + edad = int(input("Ingrese su edad: ")) + + if edad < 0: + raise EdadInvalida("La edad no puede ser negativa.") + + print(f"Edad: {edad}") + +except EdadInvalida as error: + + print(error) + +except ValueError: + + print("Debe ingresar un número entero.") + +finally: + + print("Fin del programa.") \ No newline at end of file diff --git a/clase_4/main.py b/clase_4/main.py new file mode 100644 index 0000000..98fd821 --- /dev/null +++ b/clase_4/main.py @@ -0,0 +1,15 @@ +#import mi_modulo +import mi_modulo as mod +#from mi_modulo import tabla, saludame + + + + +mod.tabla(2) +print(mod.saludame("Pau")) +#mi_modulo.tabla(2) +#print(mi_modulo.saludame("Cristian")) + +from my_package import herramientas, pruebas +pruebas.probando() +herramientas.nombreCompleto("Nair", "Galarza") \ No newline at end of file diff --git a/clase_4/mi_modulo.py b/clase_4/mi_modulo.py new file mode 100644 index 0000000..c6fdeed --- /dev/null +++ b/clase_4/mi_modulo.py @@ -0,0 +1,9 @@ +def tabla (numero): + print(f"tabla de multiplicar del : {numero}") + for contador in range(1,13): + operacion = numero * contador + print(f"{numero} x {contador} = {operacion}") + +def saludame(nombre): + saludo= f"Hola {nombre} , cómo estás?" + return saludo diff --git a/clase_4/modulos y paquetes.png b/clase_4/modulos y paquetes.png new file mode 100644 index 0000000..86dd2a0 Binary files /dev/null and b/clase_4/modulos y paquetes.png differ diff --git a/clase_4/modulos_python.py b/clase_4/modulos_python.py new file mode 100644 index 0000000..d6b1332 --- /dev/null +++ b/clase_4/modulos_python.py @@ -0,0 +1,32 @@ +import math + +print(math.sqrt(64)) # Raíz cuadrada +print(math.pow(2,5)) # Potencia +print(math.pi) # Número PI +print(math.factorial(5)) # Factorial + +################################################## + +import random + +print(random.randint(1,10)) + +colores = ["Rojo","Azul","Verde"] + +print(random.choice(colores)) + +################################################## + +import datetime + +print(datetime.date.today()) + +fecha_completa = datetime.datetime.now() +print(fecha_completa) +print(fecha_completa.day) +print(fecha_completa.month) +print(fecha_completa.year) + +fecha_personalizada= fecha_completa.strftime("%d-%m-%Y") + +print(fecha_personalizada) \ No newline at end of file diff --git a/clase_4/my_package/__init__.py b/clase_4/my_package/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/clase_4/my_package/herramientas.py b/clase_4/my_package/herramientas.py new file mode 100644 index 0000000..67dcf6f --- /dev/null +++ b/clase_4/my_package/herramientas.py @@ -0,0 +1,2 @@ +def nombreCompleto(nombre, apellido): + print(f"El nombre es {nombre} y el apellido es {apellido}") \ No newline at end of file diff --git a/clase_4/my_package/pruebas.py b/clase_4/my_package/pruebas.py new file mode 100644 index 0000000..e98c9d4 --- /dev/null +++ b/clase_4/my_package/pruebas.py @@ -0,0 +1,2 @@ +def probando(): + print("esto es una prueba de un modulo dentro de un paquete") \ No newline at end of file diff --git a/ejemplo.py b/ejemplo.py new file mode 100644 index 0000000..c081604 --- /dev/null +++ b/ejemplo.py @@ -0,0 +1,4 @@ +contador = 5 +while contador > 0: + print (contador) + contador -= 1 \ No newline at end of file