# Division by Zero problem

Page 1 of 1

## 1 Replies - 350 Views - Last Post: 08 September 2013 - 06:00 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=328667&amp;s=3f1bd6738ad98e9e886d2039d9818730&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Sandals456

Reputation: 0
• Posts: 44
• Joined: 02-February 13

# Division by Zero problem

Posted 08 September 2013 - 05:59 PM

Hello all,

I need help with an assignment in which I have the user input two integers which will then perform division. If the numerator is 0, then it should print out 'INF', and same goes for the denominator.

For example:

a = 71
b = 4
17.75
0.056338028169014086
================================

a = 0
b = 4
0.0
INF
================================

a = 4
b = 0
INF
INF

This is my code so far:
```#Calling out variables
numerator_int = input("a = ")
denominator_int = input("b = ")
#The operands for the two user inputs
quotient1_int = float(numerator_int)/float(denominator_int)
quotient2_int = float(denominator_int)/float(numerator_int)

#Numerator if
if numerator_int == float(0):
print numerator_int
print("INF")
#Denominator if
elif denominator_int == float(0):
print ("INF")
print denominator_int
#If both numerator and denominator is zero
elif numerator_int and denominator_int == float(0):
print ("INF")
print ("INF")

else:
print quotient1_int
print quotient2_int

```

When I run the code and input zero to the numerator or denominator, I get the error code claiming that when either number is on the denominator, it doesn't exist since dividing by zero is impossible.

How would I be able to overcome this?

Is This A Good Question/Topic? 0

## Replies To: Division by Zero problem

### #2 andrewsw

• RequestedRangeNotSatisfiable

Reputation: 6554
• Posts: 26,569
• Joined: 12-December 12

## Re: Division by Zero problem

Posted 08 September 2013 - 06:00 PM

Duplicate post closed.