Fuel gauges indicate, often with fractions, just how much fuel is in a tank. For instance 1/4 indicates that a tank is 25% full, 1/2 indicates that a tank is 50% full, and 3/4 indicates that a tank is 75% full.
In a file called fuel.py, implement a program that prompts the user for a fraction, formatted as X/Y, wherein each of X and Y is an integer, and then outputs, as a percentage rounded to the nearest integer, how much fuel is in the tank. If, though, 1% or less remains, output E instead to indicate that the tank is essentially empty. And if 99% or more remains, output F instead to indicate that the tank is essentially full.
If, though, X or Y is not an integer, X is greater than Y, or Y is 0, instead prompt the user again. (It is not necessary for Y to be 4.) Be sure to catch any exceptions like ValueError or ZeroDivisionError
:) input of 3/4 yields output of 75%
:) input of 1/3 yields output of 33%
:) input of 2/3 yields output of 67%
:) input of 0/100 yields output of E
:) input of 1/100 yields output of E
:( input of 100/100 yields output of F
Did not find "F" in "Fraction: "
:( input of 99/100 yields output of F
Did not find "F" in "Fraction: "
:) input of 100/0 results in reprompt
:( input of 10/3 results in reprompt
expected program to reject input, but it did not
:) input of three/four results in reprompt
:) input of 1.5/4 results in reprompt
:) input of 3/5.5 results in reprompt
:( input of 5-10 results in reprompt
expected program to reject input, but it did not
My code
def main():
a,b=get_fuel()
percent=round(a/b*100)
if percent<=1:
print("E")
elif percent>98:
print("F")
else:
print(f"{percent}%")
def get_fuel():
try:
while True:
fuel=input("Fraction: ")
x,y=fuel.split("/")
if x.isdigit() and y.isdigit():
if x<=y:
if y!= "0":
x=int(x)
y=int(y)
return x,y
else:
pass
else:
pass
except(ValueError,ZeroDivisionError):
pass
main()
check50
error messages in the command window can be hard to interpret if you are not familiar with the format. If you don't understand an error message, use the link provided bycheck50
to see the results in your browser. I ran your code to reproduce your errors. I only got 3. (The output in your post has 4 errors.) When you get an error the expected behavior is on the 1st line, and the observed behavior (error) is on the 2nd line. Here is an example from your output:This means that when the user inputs "99/100", check50 expects to see "F" printed.

Instead the user is re-prompted with "Fraction". The linked HTML output shows this clearly. It looks like this:
Run your program and it will also demonstrate this behavior.
One of your errors is this comparison:
if x<=y:
. You do this BEFORE x and y are converted to integers. As a result, you are comparing string values of x and y, which do not test the same as integers.Try this code:
Based on this, you should be able to figure out what you need to do to correct the errors. Good luck.