t | from fractions import Fraction | t | from fractions import Fraction |
| inp = input() | | inp = input() |
| number_flag = False | | number_flag = False |
| number_acc = '' | | number_acc = '' |
| result_string = '' | | result_string = '' |
| | | |
| def dec2frac(number): | | def dec2frac(number): |
| tmp = number.split('.') | | tmp = number.split('.') |
| if len(tmp) == 1: | | if len(tmp) == 1: |
| return f"Fraction('{number}')" | | return f"Fraction('{number}')" |
| dec = 10 ** len(tmp[1]) | | dec = 10 ** len(tmp[1]) |
| return f"Fraction('{tmp[0]}{tmp[1]}/{dec}')" | | return f"Fraction('{tmp[0]}{tmp[1]}/{dec}')" |
| for char in inp: | | for char in inp: |
| if char in ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'): | | if char in ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'): |
| number_flag = True | | number_flag = True |
| number_acc += char | | number_acc += char |
| else: | | else: |
| if number_flag: | | if number_flag: |
| result_string += dec2frac(number_acc) | | result_string += dec2frac(number_acc) |
| number_acc = '' | | number_acc = '' |
| number_flag = False | | number_flag = False |
| result_string += char | | result_string += char |
| if number_flag: | | if number_flag: |
| result_string += dec2frac(number_acc) | | result_string += dec2frac(number_acc) |
| print(eval(result_string)) | | print(eval(result_string)) |