+ 1
Why does it raise an error even though I put an else instead of it?
6 Antworten
+ 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 :)")
+ 1
Would love to help out, could you post the code maybe? :)
+ 1
Whoops, just added
+ 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 :)
+ 1
So how can I fix it?
0
Thanks!