Introdução ao try e except para capturar erros (exceptions)
This commit is contained in:
20
aula29.py
20
aula29.py
@@ -3,23 +3,19 @@ Introdução ao try/except
|
|||||||
try -> tentar executar o código
|
try -> tentar executar o código
|
||||||
except -> ocorreu algum erro ao tentar executar
|
except -> ocorreu algum erro ao tentar executar
|
||||||
"""
|
"""
|
||||||
from curses.ascii import isdigit
|
numero_str = input(
|
||||||
from re import L
|
'Vou dobrar o número que vc digitar: '
|
||||||
|
)
|
||||||
numero_str = input('Digite um número: ')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print('STR:', numero_str, type(numero_str))
|
numero_float = float(numero_str)
|
||||||
numero_int = int(numero_str)
|
print('FLOAT:', numero_float)
|
||||||
print('INT:', numero_int, type(numero_int))
|
print(f'O dobro de {numero_str} é {numero_float * 2:.2f}')
|
||||||
print(numero_int * 3)
|
|
||||||
except:
|
except:
|
||||||
print('Isso não é um número')
|
print('Isso não é um número')
|
||||||
|
|
||||||
# if numero_str.isdigit():
|
# if numero_str.isdigit():
|
||||||
# print('STR:', numero_str, type(numero_str))
|
# numero_float = float(numero_str)
|
||||||
# numero_int = int(numero_str)
|
# print(f'O dobro de {numero_str} é {numero_float * 2:.2f}')
|
||||||
# print('INT:', numero_int, type(numero_int))
|
|
||||||
# print(numero_int * 3)
|
|
||||||
# else:
|
# else:
|
||||||
# print('Isso não é um número')
|
# print('Isso não é um número')
|
||||||
|
|||||||
Reference in New Issue
Block a user