Fraction | Function to return gcd of a and b ; Function to convert the obtained fraction into it 's simplest form ; Finding gcd of both terms ; Converting both terms into simpler terms by dividing them by common factor ; Function to add two fractions ; Finding gcd of den1 and den2 ; Denominator of final fraction obtained finding LCM of den1 and den2 LCM * GCD = a * b ; Changing the fractions to have same denominator Numerator of the final fraction obtained ; Calling function to convert final fraction into it 's  simplest form ; Driver Code
def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return gcd ( b % a , a ) NEW_LINE DEDENT def lowest ( den3 , num3 ) : NEW_LINE INDENT common_factor = gcd ( num3 , den3 ) NEW_LINE den3 = int ( den3 / common_factor ) NEW_LINE num3 = int ( num3 / common_factor ) NEW_LINE print ( num3 , " / " , den3 ) NEW_LINE DEDENT def addFraction ( num1 , den1 , num2 , den2 ) : NEW_LINE INDENT den3 = gcd ( den1 , den2 ) NEW_LINE den3 = ( den1 * den2 ) / den3 NEW_LINE num3 = ( ( num1 ) * ( den3 / den1 ) + ( num2 ) * ( den3 / den2 ) ) NEW_LINE lowest ( den3 , num3 ) NEW_LINE DEDENT num1 = 1 ; den1 = 500 NEW_LINE num2 = 2 ; den2 = 1500 NEW_LINE print ( num1 , " / " , den1 , " ▁ + ▁ " , num2 , " / " , den2 , " ▁ is ▁ equal ▁ to ▁ " , end = " " ) NEW_LINE addFraction ( num1 , den1 , num2 , den2 ) NEW_LINE