Advertisement
ssoni

fuel.py

Jan 10th, 2024 (edited)
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def main():
  2.  
  3.     while True:
  4.         try:
  5.             fraction = input('Fraction: ')
  6.             parts = fraction.split('/')
  7.             numer = int(parts[0])
  8.             denom = int(parts[1])
  9.             if numer>denom:
  10.                 continue
  11.             pct = round((numer / denom) * 100)
  12.         except ValueError:
  13.             continue
  14.         except ZeroDivisionError:
  15.             continue
  16.         except:
  17.             continue
  18.         else:
  19.             if pct >= 99:
  20.                 print('F')
  21.             elif pct <= 1:
  22.                 print('E')
  23.             else:
  24.                 print(f'{pct}%')
  25.             break
  26.  
  27. main()
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement