Created
December 23, 2018 16:46
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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