Skip to main content

Method 1:

try: value = a/b except ZeroDivisionError: value = float('Inf') 

orMethod 2:

if b != 0: value = a / b else: value = float('Inf') 

But be aware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.

try: value = a/b except ZeroDivisionError: value = float('Inf') 

or

if b != 0: value = a/b else: value = float('Inf') 

But be aware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.

Method 1:

try: value = a/b except ZeroDivisionError: value = float('Inf') 

Method 2:

if b != 0: value = a / b else: value = float('Inf') 

But be aware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.

spelling
Source Link
glglgl
  • 91.5k
  • 13
  • 157
  • 230
try: value = a/b except ZeroDivisionError: value = float('Inf') 

or

if b != 0: value = a/b else: value = float('Inf') 

But bewarebe aware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.

try: value = a/b except ZeroDivisionError: value = float('Inf') 

or

if b != 0: value = a/b else: value = float('Inf') 

But beware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.

try: value = a/b except ZeroDivisionError: value = float('Inf') 

or

if b != 0: value = a/b else: value = float('Inf') 

But be aware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.

Source Link
glglgl
  • 91.5k
  • 13
  • 157
  • 230

try: value = a/b except ZeroDivisionError: value = float('Inf') 

or

if b != 0: value = a/b else: value = float('Inf') 

But beware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.