import fractions  
  
f1 = fractions.Fraction(7, 8)  
f2 = fractions.Fraction(1, 2)  
  
print('{} + {} = {}'.format(f1, f2, f1 + f2))  
print('{} - {} = {}'.format(f1, f2, f1 - f2))  
print('{} * {} = {}'.format(f1, f2, f1 * f2))  
print('{} / {} = {}'.format(f1, f2, f1 / f2))

Output :

7/8 + 1/2 = 11/8
7/8 - 1/2 = 3/8
7/8 * 1/2 = 7/16
7/8 / 1/2 = 7/4

Add a Comment

Add a Comment