-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq3.py
27 lines (22 loc) · 688 Bytes
/
q3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Assignment week_4, question 3
from math import gcd
def lcm(*input):
# This function returns the LCM value for 2 or more given inputs
lcmm = input[0]
for i in range(1,len(input)):
lcmm = lcmm * input[i]//gcd(lcmm, input[i])
return lcmm
print("Welcome to LCM calculator: ")
while True:
try:
user_input = []
# take 4 inputs
for i in range(1, 5):
a = int(input("Enter input number " + str(i) + " : "))
user_input.append(a)
except ValueError:
print("Invalid entry, please enter inegers")
continue
else:
print("The LCM for the entered inputs is:", lcm(*user_input))
break