36 lines
697 B
Python
36 lines
697 B
Python
def main():
|
|
while True:
|
|
fuel = input("Fraction:\t\t")
|
|
try:
|
|
result = convert(fuel)
|
|
break
|
|
except (ValueError, ZeroDivisionError):
|
|
continue
|
|
print(gauge(result))
|
|
|
|
|
|
|
|
def convert(fraction: str) -> int:
|
|
try:
|
|
x, y = map(int, fraction.split('/'))
|
|
except (ValueError, TypeError):
|
|
raise ValueError
|
|
if x > y:
|
|
raise ValueError
|
|
if y == 0:
|
|
raise ZeroDivisionError
|
|
return int(round(x / y*100, 0))
|
|
|
|
|
|
def gauge(percentage):
|
|
if percentage <= 1:
|
|
return "E"
|
|
elif percentage >= 99:
|
|
return "F"
|
|
else:
|
|
return f"{percentage}%"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|