Factor every element of list in python, then append factors to sub-arrays in another array -
Here's my target factor every single element in the first and second positions, all the factors Adding to Public Man and PQN 3, which will then be linked to the main lists pqnum2 (for the first factor) and pqnum4 (for the secured factors) In addition, the first and secondary can be added by the user ( Has not been shown). Below is the code: Expected output is: But the output that comes out of the code: I was thinking about it for days I can not know why, please you do not reset any of your variables O When you code your <> Febe & lt; = X: For the first time the loop crosses, after the Once you fix this, you will see that the list of factors of your
define suggested lists pqnum = [] pqnum2 = [] pqnum3 = [] pqnum4 = [] # when loop counters are fib = 1 sib = 1 # listings findings Remove (user can be added) first = = 24, -1, 1, 0, -800, 2, 6] seconds = [2, -1, 1, 1, 30, 11, 5] # The first category for the factor index (0, lane (first) -1): x = first [index] while fib & lt; = X: if x% fib == 0: pqnum.append (fib) pqnum.append (-fib) fib = fib + 1 pqnum2.append (pqnum) print pqnum2 #factor indexed in index range (0, lane (secondary) -1): While sib & lt; = Secured [index]: if the second option [index]% sib == 0: pqnum3.append (sib) pqnum3.append (-sib) sib = sib + 1 pqnum4.append (pqnum3) print pqnum4
[[1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8 , [1, -1, 2, - 12, -12, 24, -24], [1, -1], [1, -1], [0], [all factors -800, positive or negative] 2], [1, -1], [1, -1], [1, - 1], [1, -1, 2, -2, 3, -3]] [1, -1, 2, -2] 1], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30], [1, -1] , 11, -11], [1, -1,5, -5]]
[ [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24], [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24], [1, - 1, 2, -2, 3, -3, 4, -4, 6, -6, 8 , -8, 12, -12, 24, -24], [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12 , 24, -24], [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24], [ 1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24]] [[1, -1, 2, -2, -3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30], [1, -1, 2, -2, 3, -3, 5, -5, 6, - 6, 10, -10, 15, -15, 30, -30], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15 , -1, 15, 30, -30 ], [1, -1, 2, -2, 3, -3, 5, -5, 6, -6, 10, -10, 15, -15, 30, -30]]
fib = 24 and
pqnum = [1, -1], 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 12, -12, 24, -24] . When you reach that loop a second time, those values do not change, so compare
phab
24 < -1 is false, and the same array is added to
pqnum in
pqnum2 .
-1 will be empty, because the comparison
fib < = X still
1 & lt; Based on your logic, I will use a full value for
x populating this clue:
#factor The first category In index (0, lane (first) -1): x = ABS (first [index]) fib = 1 pqnum = [] while Fib & Lt; = X: if x% fib == 0: pqnum.append (fib) pqnum.append (-fib) fib = fib + 1 pqnum2.append (pqnum) print pqnum2 < / Html>
Comments
Post a Comment