Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def AllFactors(num):
- res = []
- for i in range(1, num):
- if num%i == 0:
- res.append(i)
- res.append(num)
- return res
- def CommonFactors(num1, num2):
- temp = AllFactors(Tnum1) + AllFactors(Tnum2)
- res = []
- for i in temp:
- if (temp.count(i) == 2) and (i not in res):
- res.append(i)
- return res
- # Main Program
- num1 = int(input("Enter 1st Number : "))
- num2 = int(input("Enter 2nd Number : "))
- Tnum1, Tnum2 = num1, num2
- ComFac = CommonFactors(Tnum1, Tnum2)
- while ComFac != [1]:
- max_ComFac = max(ComFac)
- Tnum1 //= max_ComFac
- Tnum2 //= max_ComFac
- ComFac = CommonFactors(Tnum1, Tnum2)
- else:
- print(f"Simplest Whole Ratio of {num1}:{num2} => {Tnum1}:{Tnum2}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement