From 6aa87585a6eaca9f5f25917c49f6fa0b0d397ef6 Mon Sep 17 00:00:00 2001 From: cmoreno Date: Thu, 20 Aug 2026 19:43:32 -0300 Subject: [PATCH] =?UTF-8?q?exc=C3=A9pciones=20personalizadas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clase_6/excep_personalizada.py | 16 ++++++++++++++++ clase_6/index.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 clase_6/excep_personalizada.py create mode 100644 clase_6/index.py diff --git a/clase_6/excep_personalizada.py b/clase_6/excep_personalizada.py new file mode 100644 index 0000000..9c508da --- /dev/null +++ b/clase_6/excep_personalizada.py @@ -0,0 +1,16 @@ + +class NumeroInvalidoError (Exception): + pass + +try: + nunero= int(input("ingrese un numero")) + + if nunero < 0 : + print("ingrese un numero entero") + raise NumeroInvalidoError +except NumeroInvalidoError: + print("ocurrio un error") +else: + print("el valor es positivo") +finally: + print("finalizado") \ No newline at end of file diff --git a/clase_6/index.py b/clase_6/index.py new file mode 100644 index 0000000..601d1c7 --- /dev/null +++ b/clase_6/index.py @@ -0,0 +1,14 @@ + +try: + + lista= ["Hola",1, 7, True] + indice= int(input("Ingrese el numero de indice")) + print(lista[indice]) +except ValueError: + print("ingrese un valor entero") +except IndexError : + print(f"ocurrió un error, error de indice") +else: + print(f"el indice es {lista[3]}") +finally: + print("Programa finalizado") \ No newline at end of file