-
Notifications
You must be signed in to change notification settings - Fork 0
/
tratarErros.py
31 lines (27 loc) · 969 Bytes
/
tratarErros.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def leia_int(valor): # função para tratamento de erros para inserção de valores inteiros
while True:
try:
n = int(input(valor))
except (ValueError, TypeError,):
print('ERRO! POR FAVOR INSIRA UM NÚMERO INTEIRO VÁLIDO')
continue
else:
return n
def leia_str(valor): # função para tratamento de erros para inserção de valores caracteres
while True:
try:
n = str(input(valor))
except (ValueError, TypeError,):
print('ERRO! POR FAVOR INSIRA APENAS CARACTERES')
continue
else:
return n
def leia_float(valor): # função para tratamento de erros para inserção de valores caracteres
while True:
try:
n = float(input(valor))
except (ValueError, TypeError,):
print('ERRO! POR FAVOR INSIRA APENAS CARACTERES')
continue
else:
return n