Skip to content

Instantly share code, notes, and snippets.

@sysuin
Created December 23, 2018 16:46
Show Gist options
  • Save sysuin/eeb5a3c7b600f208f61c8ba25d44c323 to your computer and use it in GitHub Desktop.
Save sysuin/eeb5a3c7b600f208f61c8ba25d44c323 to your computer and use it in GitHub Desktop.
You are given four numbers num1, den1, num2, and den2. You need to find (num1/den1)+(num2/den2) and output the result in the form of (numx/denx).
def addFraction(num1, den1, num2, den2):
from math import gcd
num = num1*den2+num2*den1
den = den1*den2
ka=gcd(num,den)
h=num//ka
d=den//ka
print(str(h)+"/"+str(d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment