def sumar_dos():
while True:
a = input('numero 1: ')
b = input('numero 2: ')
try:
resultado = int(a) + int(b)
except ValueError as e:
print('te pedi un numero salame ')
print(f'ERROR:{type(e).__name__}')
else:
break
finally:
print('esto se ejecuta siempre')
return resultado
print(sumar_dos())
#i execute this code and it makes an exception without executing the except part and when i run the code again the except message apears in the console
how can i run the except without trigering an exception ?
thanks for reading
saludos desde argentina
To enter code, use three of these: ~ in series (the key is just underneath the esc key. Press it along with the shift key. There should be three in series as in: ~~~) Include this series both above and below your code so that it appears as code here.
#i execute this code and it makes an exception without executing the
except part and when i run the code again the except message apears in
the console
how can i run the except without trigering an exception ?
Can you show us a transcrypt of the code failing? i.e. copy/paste a run
of the code doing the wrong thing, again between code fences, eg:
```
paste the output here
```
I can only assume that somehow you’re getting an exception which is not
a ValueError. But it isn’t clear without seeing your inputs and a run
doing the wrong thing.
Exception has occurred: ValueError
invalid literal for int() with base 10: 'hi '
File "C:\Users\Usuario\Desktop\python de elbio el mas crack\excepciones\excepciones.py", line 6, in sumar_dos
resultado = int(a) + int(b)
^^^^^^
File "C:\Users\Usuario\Desktop\python de elbio el mas crack\excepciones\excepciones.py", line 16, in <module>
print(sumar_dos())
ValueError: invalid literal for int() with base 10: 'hi '