Python Exceptions | SoloLearn: Learn to code for FREE!


Python Exceptions

How come if I change the '0' to 'input' it doesn't come up with the "divided by zero error" try: print("Hello") print(1 / input) except ZeroDivisionError: print("Divided by zero") finally: print("This code will run no matter what")

12/30/2018 11:52:37 AM

Matt Harrison

2 Answers

New Answer


Do you mean, you input 0 and it doesn't work like you expected? Input is always in string format, so you're not dividing by 0, but by '0', which also doesn't work, but for other reasons. You also (at least here) do not call the input function, because the parentheses after input are missing. So you're dividing by a function name which still doesn't work, again for other reasons. Change the line to print(1/int(input())) and you should get your ZeroDivisionError again (as long as you input zero).


HonFu Thanks mate!