Issue
I need help to solve Project Euler problem 3 with list.append(). If I put print like above it's going forever. How can I read the entire list?
# What is the largest prime factor of the number 600851475143?
list =[0]
for i in range(2,600851475143):
if(600851475143%i==0):
list.append(i)
print(list)
Solution
So for your particular problem, you would put the print function outside the for loop because you just want to print the final product which is the largest prime factor of the number 600851475143. And in your code you're appending to the list which again means you should put the print function outside the for loop like below:
list =[0]
for i in range(2,600851475143):
if(600851475143%i==0):
list.append(i)
print(list)
If you put it inside, you would be printing "i" each time it is getting looped and added to the list and you don't want that:
list =[0]
for i in range(2,600851475143):
if(600851475143%i==0):
list.append(i)
print(list)
Answered By - VintageMind
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.