Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Divisors shared the second numbers mircea_dragu Unladen Swallow Posts: 1 Threads: 1 Joined: Feb 2019 Reputation: 0 Likes received: 0 #1 Feb-07-2019, 08:18 PM (This post was last modified: Feb-07-2019, 10:02 PM by micseydel. Edited 1 time in total. Edit Reason: Quote tags -> Python tags. ) I am a beginer in Python's programming, so i began with easy programming problems. The goal is to show the divisors shared by the two numbers entered by the user. I cannot figure out where is my mistake when i try to store in z list the divisors shared by the two numbers. ```a = int(input("\n Enter first number a = ")) b = int(input("\n Enter a 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)) ``` ichabod801 Bunny Rabbit Posts: 4,231 Threads: 94 Joined: Sep 2016 Reputation: 271 Likes received: 1262 #2 Feb-07-2019, 10:09 PM You should iterate over the list, not the indexes of the list, as shown here. Your last loop should use the in operator: ```for m in x: if m in y: z.append(n) ``` Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 377 May-09-2019, 12:19 PM Last Post: Pleiades Populating a list with divisors RedSkeleton007 1 537 Aug-21-2018, 12:52 AM Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)