Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14040

Why is my exception getting printed twice?

$
0
0

The following code looks good to me, but when I use e0 with my except ValueError it prints twice, please help my slow brain

my inputs are 20.5 and 5

try:    user_num = int(input())    div_num = int(input())    print(user_num / div_num)except ValueError as e0:    print('Input Exception: invalid literal for int() with base 10:', e0)except ZeroDivisionError:    print('Zero Division Exception: integer division or modulo by zero')

Output

Input Exception: invalid literal for int() with base 10: invalid literal for int() with base 10: '20.5'

Tried to remove e0, print my entire statement without e0, perfectly prints, but I cannot put the e0 otherwise it just prints the output twice for some reason.


Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>