Help me in solving PYTHCL85 problem

My issue

There is a sample code present in IDE, which inputs two number and prints their division.
If you run the code for a test case like 3 0 you will get the runtime error.
To fix it, add an if condition which checks if the value of b is 0 and output infinity directly. Otherwise output the result of division.

My code

a, b = map(int, input().split())
c = a//b
if b==0:
  print("infinity")

Learning course: ATT - Python
Problem Link: Runtime error Practice Problem in ATT - Python - CodeChef

Mmmmh, what’s your question?
Sadly, you are refering a private content, so we can’t see the content.

However, that code will throw Runtime Error if b = 0

A computer will follow the statements one by one. The processor does not know what’s next until the statement arrives. I spot this because you first make the division, and then make the if conditional. If “b” happens to be “0” it will try a // b, and that will throw the Runtime Error.

What ATT-Python code is probably teaching you is that Runtime Error is somehow the processor crying because you threw something at it that it can not handle with. A division by zero is one of those things that the processor can’t handle with.

If you think that an statement might be reckless, you should warn the processor, so it can handle with it, like this:

a, b = map(int, input().split())
if b==0:
    print("infinity")
else:
    c = a // b

Or this:

a, b = map(int, input().split())
try:
    c = a // b
except:
    print('infinity')