+ 2

I am not getting this. Can you explain what can be the result. "What'll be the greatest number output in the code?"

try: for i in range(5): print(1/i) except : print(0)

31st Mar 2022, 5:12 PM
Md Arif Shahriyar Sohan
Md Arif Shahriyar Sohan - avatar
2 Respuestas
+ 7
It'll be 0. You tried to go through a for loop and print 1 divided by each number. The first number in a regular range is 0. You can't divide by zero because the world will implode. Python saves us by catching the error though. So it hops down to the "except" portion of the code (when you don't specify an error it will trigger if ANY error is detected) and executes it's single line, then terminates the program
31st Mar 2022, 5:25 PM
Slick
Slick - avatar