Skip to content

Commit 6fb3bfb

Browse files
committed
#10 - python
1 parent 9715f7b commit 6fb3bfb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#Excepciones y errores
2+
3+
try:
4+
print(10/1)
5+
6+
my_list = [1,2,3,4]
7+
print(my_list[4])
8+
9+
except Exception as e:
10+
print(f"ERROR: {e}")
11+
12+
print("Hola a todos")
13+
14+
15+
#EJERCICIO EXTRA
16+
17+
class StrTypeError(Exception):
18+
pass
19+
20+
def extra(param:list):
21+
22+
if len(param) < 3:
23+
raise IndexError()
24+
elif param[1] == 0:
25+
raise ZeroDivisionError()
26+
elif type(param[2]) != str:
27+
raise StrTypeError("El tercer elemento debe de ser una cadena de texto")
28+
29+
print(param[2])
30+
print(param[0]/param[1])
31+
32+
33+
try:
34+
extra([1,2,"Hola"])
35+
except IndexError as e:
36+
print("ERROR: el numero de elementos de la lista debe ser mayor de 2")
37+
except ZeroDivisionError as e:
38+
print("ERROR: el segundo elemento de la lista no puede ser cero")
39+
except StrTypeError as e:
40+
print(f"ERROR: {e}")
41+
except Exception as e:
42+
print(f"ERROR inesperado: {e}")
43+
finally:
44+
print("FIN")

0 commit comments

Comments
 (0)