The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



Thread: Python
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 04-16-2002
Perderabo's Avatar
Perderabo Perderabo is offline
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,718
I too do not know python. But it looks like you line "for j in range(2,i)" will vary j starting at 2 and going up to either i or i-1, I'm not sure which from this thread. But either way, it looks like your final test in the loop is to see if j equals i+1. How can that ever happen?

In any event, your problem isn't python, it's the algorithm. Your inner loop is finding factors. Before you enter that inner loop, set "nfactor=0". Each time you find a factor and do the "print j", also increment nfactor. After the inner loop finishes, test nfactor...if it's zero, "print prime".
Reply With Quote