excépciones personalizadas
This commit is contained in:
parent
d0f39b6ab5
commit
6aa87585a6
16
clase_6/excep_personalizada.py
Normal file
16
clase_6/excep_personalizada.py
Normal file
|
|
@ -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")
|
||||
14
clase_6/index.py
Normal file
14
clase_6/index.py
Normal file
|
|
@ -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")
|
||||
Loading…
Reference in New Issue
Block a user