-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFuel Gauge
More file actions
29 lines (24 loc) · 779 Bytes
/
Fuel Gauge
File metadata and controls
29 lines (24 loc) · 779 Bytes
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
def main():
while True:
try:
fraction = input("Fraction: ")
x, y = fraction.split("/")
x = int(x)
y = int(y)
if y == 0:
continue # Can't divide by zero
if x > y:
continue # Invalid fraction
percent = round((x / y) * 100)
if percent <= 1:
print("E")
elif percent >= 99:
print("F")
else:
print(f"{percent}%")
break # Exit the loop once valid input is handled
except (ValueError, ZeroDivisionError):
# If input is not valid (e.g., not integers or can't split), try again
continue
if __name__ == "__main__":
main()