Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##5 Kyu - Common Denominators
- def is_common(arr, test_den):
- for j in range(len(arr)):
- if test_den % arr[j][1] != 0: ##Check all denominators are factors of test
- return False
- return True
- def convertFracts(lst):
- max_d = 0 ##Variable to hold largest existing denominator
- for i in range(len(lst)): ##Find the largest denominator in lst
- if lst[i][1] > max_d:
- max_d = lst[i][1]
- play = True
- counter = 2
- test = 0 ##Just to keep test in the right scope for for loop below
- while play == True:
- test = max_d * counter ##Creates test lowest common denominator
- if not is_common(lst, test): ##Test not valid for all denominators
- counter += 1
- else: ##Test is valid, break out of loop
- play = False
- for k in lst:
- factor = test//k[1] ##how to get to lowest common denominator
- for m in range(len(k)): ##raises all values to match lowest common denominator
- k[m] = k[m] * factor
- return lst
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement