Skip to content

Commit 6b10c14

Browse files
authored
Merge pull request #11 from kelvinchanwh/master
Find lowest common denominator
2 parents eb865a5 + bba93db commit 6b10c14

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lcm.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from math import *
2+
3+
#Calculates Lowest Common Multiple
4+
def compute_lcm(x, y):
5+
6+
# Select larger number
7+
if x > y:
8+
larger = x
9+
else:
10+
larger = y
11+
12+
# Checks if the larger value is divisible by both numbers
13+
while((larger % x != 0) or (larger % y != 0)):
14+
# If not divisible by either number, the larger value is incremented by 1
15+
larger += 1
16+
17+
return larger
18+
19+
in1 = int(input("Insert 1st number: "))
20+
in2 = int(input("Insert 2nd number: "))
21+
22+
print("LCM of %d and %d is"%(in1, in2), compute_lcm(in1, in2))

0 commit comments

Comments
 (0)