t | import re | t | import re |
| from fractions import Fraction | | from fractions import Fraction |
| | | |
| def digit(string): | | def digit(string): |
| if string.isdigit(): | | if string.isdigit(): |
| return True | | return True |
| try: | | try: |
| float(string) | | float(string) |
| return True | | return True |
| except ValueError: | | except ValueError: |
| return False | | return False |
| my_str = input().replace(' ', '') | | my_str = input().replace(' ', '') |
| my_mas = [i for i in re.split('(\\+|\\-|\\*|\\(|\\)|\\/|\\%)', my_str) if i != ''] | | my_mas = [i for i in re.split('(\\+|\\-|\\*|\\(|\\)|\\/|\\%)', my_str) if i != ''] |
| new_str = '' | | new_str = '' |
| for i in my_mas: | | for i in my_mas: |
| if digit(i): | | if digit(i): |
| new_str += 'Fraction(' + i + ').limit_denominator()' | | new_str += 'Fraction(' + i + ').limit_denominator()' |
| else: | | else: |
| new_str += i | | new_str += i |
| print(eval(new_str)) | | print(eval(new_str)) |