Error in the below program

while True:
    fact = input("Fraction: ")
        num, denom = fact.split("/")
        x = int(num)
        y = int(denom)
        f = x/y
        if f <= 1:
    except (ValueError, ZeroDivisionError):
p = int(round(f * 100))
if p <= 1:
if p >= 99:

If i give 0/4 it gave result “E” and 0%,
but i need only “E” as a result. Help please

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

the first if runs and prints E
then the second if runs and switches down to the else so it prints out the percentage.

How do you think you can stop this from happening?

Thank you, I will follow for sure.

1 Like

I don’t know, if i want to end the first if after the it got true?

You may want to try using an elif statement

Take a look for examples on this here

Thank you, Its worked.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.