# Division by Zero problem

Page 1 of 1

## 1 Replies - 203 Views - Last Post: 08 September 2013 - 06:00 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=328667&amp;s=3114938846e0bfbc1931f05f97c250d4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Sandals456

• New D.I.C Head

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

• I'm not here to twist your niblets

Reputation: 4276
• Posts: 15,682
• Joined: 12-December 12

## Re: Division by Zero problem

Posted 08 September 2013 - 06:00 PM

Duplicate post closed.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }