In: Computer Science
IN PYTHON :
Write one program that will compute both the Least Common Multiple, and the Greatest Common Factor of two numbers inputted by a user.
The program will display all factors and multiples of the two numbers.
When displaying the multiples of the numbers, only display up to the first input times the second input. \
Use functions to computer the answers.
Loop the program so that the user can enter two new numbers after each try.
Code for copying
t=int(input("How many times you want to check : "))
m=0
while m<t:
print("case {}".format(m+1))
n1=int(input("Enter first number : "))
n2=int(input("Entersecond number : "))
list1=[]
list2=[]
list3=[]
for i in range(1,n1+1):
if n1%i==0:
list1.append(i)
for i in range(1,n2+1):
if n2%i==0:
list2.append(i)
for i in range(1,n1+1):
list3.append(n2*i)
def p1(n1,n2):
while(n2):
n1, n2 = n2, n1 % n2
return n1
def p2(n1,n2):
return
(n1*n2)/p1(n1,n2)
print("Gcd is {}
".format(p1(n1,n2)))
print("LCM is {}
".format(p2(n1,n2)))
print("factors of {} = {}
".format(n1,list1))
print("factors of {} = {}
".format(n2,list2))
print("multiples of {} = {}
".format(n2,list3))
m+=1