Why does it raise an error even though I put an else instead of it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does it raise an error even though I put an else instead of it?

Help https://code.sololearn.com/c1Ac0x0WfC45/?ref=app

11th Jul 2018, 2:56 PM
Raphael Shay
Raphael Shay - avatar
6 Answers
+ 1
you need to refactor your condition line 17: 1) to avoid exception for 0 just look what it says when you enters 0: last line says "ZeroDivisionError : division by zero" so you can easily catch the error with a try /except bloc searching for a ZeroDivisionError: try: a=1/0 except ZeroDivisionError: print("nope") 2) to test if variable is an integer you can use something like if type(variable)==int: print("I'm an integer :)")
12th Jul 2018, 4:53 AM
darrencweid
darrencweid - avatar
+ 1
Would love to help out, could you post the code maybe? :)
11th Jul 2018, 3:57 PM
John Romby
John Romby - avatar
+ 1
Whoops, just added
11th Jul 2018, 4:12 PM
Raphael Shay
Raphael Shay - avatar
+ 1
This only raises an error for 0 since it's not possible in the division. In any other cases, condition is always true and anyway the raise instruction cannot be reached :)
11th Jul 2018, 5:12 PM
darrencweid
darrencweid - avatar
+ 1
So how can I fix it?
11th Jul 2018, 5:33 PM
Raphael Shay
Raphael Shay - avatar
0
Thanks!
12th Jul 2018, 5:04 AM
Raphael Shay
Raphael Shay - avatar