From d51c2eedf2492782bc5fe6cdc852e004a664e7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Wed, 26 Oct 2022 19:53:43 -0300 Subject: [PATCH] =?UTF-8?q?Introdu=C3=A7=C3=A3o=20ao=20try=20e=20except=20?= =?UTF-8?q?para=20capturar=20erros=20(exceptions)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula29.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/aula29.py b/aula29.py index 61f3f1c..8fbe823 100644 --- a/aula29.py +++ b/aula29.py @@ -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')