Develop a Python application which will accept n non-negative integers and will display the DIVISORS of each number then will determine the COMMON DIVISORS of the input integers.
Sample Output:
How many numbers? 4
Input Number 1: 10
Input Number 2: 50
Input Number 3: 15
Input Number 4: 20
Divisors
10: 1 2 5 10
50: 1 2 5 25 10 50
15: 1 3 5 15
20: 1 2 5 10 20
COMMON Divisors is/are: 1 5
I need the code to have an output stated above.
n = int(input("How many numbers?: "))
numbers = [0] * n
divisors = []
common = []
for i in range(n):
numbers[i] = int(input(f"Input Number {i+1}: "))
divisors.append([])
for j in range(1, numbers[i]+1):
if (numbers[i] % j) == 0:
divisors[i].append(j)
print()
print("Divisors")
for i in range(n):
print(f"{numbers[i]}: ", end="")
for j in range(len(divisors[i])):
print(f"{divisors[i][j]} ", end="")
print()
print()
print("COMMON Divisors is/are: ", end="")
for i in range(len(divisors[0])):
cnt = 0
for j in range(1, n):
for k in range(len(divisors[j])):
if divisors[j][k] == divisors[0][i]:
cnt += 1
break
if cnt == (n-1):
common.append(divisors[0][i])
for i in range(len(common)):
print(common[i], end=" ")
Comments
Leave a comment