Introdução ao try e except para capturar erros (exceptions)

This commit is contained in:
Luiz Otávio
2022-10-26 19:53:43 -03:00
parent 994504059d
commit d51c2eedf2

View File

@@ -3,23 +3,19 @@ Introdução ao try/except
try -> tentar executar o código
except -> ocorreu algum erro ao tentar executar
"""
from curses.ascii import isdigit
from re import L
numero_str = input('Digite um número: ')
numero_str = input(
'Vou dobrar o número que vc digitar: '
)
try:
print('STR:', numero_str, type(numero_str))
numero_int = int(numero_str)
print('INT:', numero_int, type(numero_int))
print(numero_int * 3)
numero_float = float(numero_str)
print('FLOAT:', numero_float)
print(f'O dobro de {numero_str} é {numero_float * 2:.2f}')
except:
print('Isso não é um número')
# if numero_str.isdigit():
# print('STR:', numero_str, type(numero_str))
# numero_int = int(numero_str)
# print('INT:', numero_int, type(numero_int))
# print(numero_int * 3)
# numero_float = float(numero_str)
# print(f'O dobro de {numero_str} é {numero_float * 2:.2f}')
# else:
# print('Isso não é um número')