๐Ÿ“ฆ jasonbanboa / python

๐Ÿ“„ fuel.py ยท 38 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38# original
import sys

def main():
    while True:
        gas = input("Fraction: ")

        p = convert(gas)
        print(gauge(p))
        break


def convert(fraction):
    while True:
        try:
            x, y = fraction.split("/")
            f = int(x) / int(y) * 100

        except (ValueError, ZeroDivisionError):
            raise

        else:
            return int(f)


def gauge(percentage):
    if percentage <= 1:
        return "E"

    elif percentage >= 99:
        return "F"

    else:
        return f"{percentage}%"


if __name__ == "__main__":
    main()