+ 1

Why doesnt this run? for i in range (0,20,2): num1 = i try: num2 = 0 print (num1 / num2) print("Done calculation") except ZeroDivisionError: print("An error occurred") print("due to zero division")

29th Sep 2016, 4:53 AM
Pavan Kumar Reddi
Pavan Kumar Reddi - avatar
9 Respostas
+ 6
Actually your program start with both num1 and num2 = 0 and it will only run once and generate those two errors An error occurred due to zero division
14th Oct 2016, 6:36 AM
Isack T Nicholaus
Isack T Nicholaus - avatar
+ 4
Your code gets ZeroDivisionError every time because num2 is assigned 0 before each division. Is that..?
29th Sep 2016, 5:00 AM
Vishal Chaudhary
Vishal Chaudhary - avatar
+ 1
your indentation should be incorrect in the actual code you are trying to run
29th Sep 2016, 5:07 AM
Vishal Chaudhary
Vishal Chaudhary - avatar
+ 1
Yes it worked. except ZeroDivisionError as err: print(str(err)) What did you do there?
29th Sep 2016, 5:31 AM
Pavan Kumar Reddi
Pavan Kumar Reddi - avatar
0
I get the Taberror at the line after "try:"
29th Sep 2016, 5:03 AM
Pavan Kumar Reddi
Pavan Kumar Reddi - avatar
0
which editor you are using?
29th Sep 2016, 5:09 AM
Vishal Chaudhary
Vishal Chaudhary - avatar
0
Im using the code playground of this app. Identation is the same used above.
29th Sep 2016, 5:12 AM
Pavan Kumar Reddi
Pavan Kumar Reddi - avatar
0
This program will run and it will print the statements in except block for every iteration in for loop because division is always done by num2 which is assigned to zero every iteration
3rd Feb 2017, 3:41 AM
Himanshu
- 3
Search my code named " pawan kumar reddy" in playground & u will get the answer
29th Sep 2016, 5:25 AM
Vishal Chaudhary
Vishal Chaudhary - avatar