0

I have this code down so far but it is asking me to use a while loop to repeatedly ask the user for a denominator for as long as the denominator is 0. Edit: I believe the code I'm missing goes in between the denominator= and if numerator = int(input...

numerator = int(input("Enter a numerator: "))
denominator = int(input("Enter denominator: "))


if numerator / denominator * denominator == numerator:
    print "Divides evenly!"
else:
    print "Doesn't divide evenly."
2
  • "It is asking you"? What "it"? Commented Jun 9, 2020 at 18:22
  • Sorry, it is a school program that I am having difficulty with. I'll post the assignment detail if you'd like. Commented Jun 9, 2020 at 18:25

2 Answers 2

2

Try this code out using try and except to catch the error of division by 0

CODE:

while True:
    numerator = int(input("Enter a numerator: "))

    denominator = int(input("Enter denominator: "))

    try:
        if numerator / denominator * denominator == numerator:
            print "Divides evenly!"
        else:
            print "Doesn't divide evenly."
    except:
        print "Sorry demoninator cannot be zero"

But does this work in python 2.x ? im not sure. Give it a try

Sign up to request clarification or add additional context in comments.

Comments

2

use a while loop: and read break instruction

numerator = int(input("Enter a numerator: "))
while True:
   denominator = int(input("Enter denominator: "))
   if denominator != 0:
       break

if numerator / denominator * denominator == numerator:
    print "Divides evenly!"
else:
    print "Doesn't divide evenly."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.