# Division by Zero problem

Page 1 of 1

## 1 Replies - 372 Views - Last Post: 08 September 2013 - 06:01 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=328669&amp;s=67c554c2abffd9ea9104690d3a739fdf&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 - 06:00 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

• blow up my boots

Reputation: 6541
• Posts: 26,471
• Joined: 12-December 12

## Re: Division by Zero problem

Posted 08 September 2013 - 06:01 PM

Duplicate post closed.