# Print the divisors shared by the two numbers

Page 1 of 1

## 4 Replies - 149 Views - Last Post: 09 February 2019 - 03:13 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=414841&amp;s=15687cceab1a6c1b81b60c185bc8de39&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mircea_dragu

Reputation: 0
• Posts: 5
• Joined: 09-February 19

# 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

### #3 mircea_dragu

Reputation: 0
• Posts: 5
• Joined: 09-February 19

## 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

• Pythonian

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....

### #5 mircea_dragu

Reputation: 0
• Posts: 5
• Joined: 09-February 19

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

Posted 09 February 2019 - 03:13 PM

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