4 Replies - 149 Views - Last Post: 09 February 2019 - 03:13 PM Rate Topic: -----

#1 mircea_dragu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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   User is offline

  • Suitor #2
  • member icon



Reputation: 14867
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 mircea_dragu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 ?
Was This Post Helpful? 0
  • +
  • -

#4 DK3250   User is online

  • Pythonian
  • member icon

Reputation: 507
  • View blog
  • 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....
Was This Post Helpful? 1
  • +
  • -

#5 mircea_dragu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1