Skip to content

Instantly share code, notes, and snippets.

@maxfire2008
Last active November 1, 2021 02:09
Show Gist options
  • Save maxfire2008/2bf5e24452f8ed2649cb1459b6a1d654 to your computer and use it in GitHub Desktop.
Save maxfire2008/2bf5e24452f8ed2649cb1459b6a1d654 to your computer and use it in GitHub Desktop.
Find lowest common multiple for a given number
import random
while True:
numbers_str = input("Enter a number to find the LCM for (csv):")
if not numbers_str:
break
numbers_int = []
for number in numbers_str.split(","):
numbers_int.append(int(number))
current = 1
while True:
is_multiple = True
current_actual = min(numbers_int)*current
for n in numbers_int:
if current_actual % int(n) != 0:
is_multiple = False
if is_multiple:
print("LCM is",current_actual)
break
current += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment