Page 1 of 1

# Print the divisors shared by the two numbers

Posted 09 February 2019 - 01:19 PM

Hi,

I am a beginer in Python programing, so i start with simple programs.
I try to find out the divisors shared by the two numbers.
I need some help. Thanks in advance.

```a = int(input("\n Enter the first number a = "))
b = int(input("\n Enter the second number b = "))

x = []
for i in range (1, a+1):
if(a % i == 0):
x.append(i)
print("\n " + str(x))

y = []
for j in range (1, b+1):
if(b % j == 0):
y.append(j)
print("\n " + str(y))

z = []
for m in range (len(x)):
for n in range (len (y)):
if(x[m] == y[n]):
z.append(n)
print("\n " + str(z))

```

Is This A Good Question/Topic? 0

## Replies To: Print the divisors shared by the two numbers

### #2 modi123_1 • • Suitor #2
•    Reputation: 14867
• Posts: 59,320
• Joined: 12-June 08

## Re: Print the divisors shared by the two numbers

Posted 09 February 2019 - 01:28 PM

What is your question?

## Re: Print the divisors shared by the two numbers

Posted 09 February 2019 - 01:33 PM

In list Z i try to put the divisors shared by the two numbers.
I don't know why, but it do not put the divisors in the list.

The question is how to put the divisors shared by the two numbers in list Z ?

### #4 DK3250 Reputation: 507
• Posts: 1,607
• Joined: 27-December 13

## Re: Print the divisors shared by the two numbers

Posted 09 February 2019 - 03:06 PM

You append the index to z, not the value....

## Re: Print the divisors shared by the two numbers

Posted 09 February 2019 - 03:13 PM

Yes, you are rigth. Now works.
Thank you.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }