<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp; Hi Ali,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp; The reason there is an error here is because 
of the seemingly innocent change </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana>... if a % x != 0 :<BR>&nbsp;&nbsp;&nbsp; .. print 
a</FONT></DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana>&nbsp; </FONT><FONT face=Arial size=2>This prints a 
every single time there is another number x, where 2 &lt;= x &lt; a and x does 
not divide a.&nbsp; Obviously, this is not what you want -- for example, 3 does 
not divide 4, but 4 is not a prime!</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp; In fact, this error persists in your first 
code example -- it tells me that 9 is prime?&nbsp; Perhaps some more thinking is 
in order ;).</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp; Please note that there are many many better 
ways to accomplish this.&nbsp; A quick search with Google will turn up many 
prime number generators for your perusal, and hopefuly conversion to python 
:).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp; HTH,</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp; Glen</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=alipolatel@yahoo.com href="mailto:alipolatel@yahoo.com">Ali 
  Polatel</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=tutor@python.org 
  href="mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, June 28, 2004 2:57 AM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> [Tutor] A problem</DIV>
  <DIV><BR></DIV>
  <DIV>&nbsp;<FONT face=Verdana>I have just started to learn python...A problem 
  has arised as I was trying to write a programme which lists the prime numbers 
  up to a definite number. I had problems to create a definition for this... 
  First what I have succeded to do is :<BR>&gt;&gt;&gt; for n in range(2, 
  10):<BR>... for x in range(2, n):<BR>... if n % x == 0:<BR>... print n, 
  'equals', x, '*', n/x<BR>... break<BR>... else:<BR>... # loop fell through 
  without finding a factor<BR>... print n, 'is a prime number'<BR>... <BR>This 
  lists the prime numbers up to 10 but when I try to create a definition 
  with:<BR>&gt;&gt;&gt; def prime(n) :<BR>... """ Hey dirty python! Show me the 
  prime numbers!! <IMG alt="" 
  src="http://www.infowar.com/forums/images/smilies/smile.gif" 
  border=0>"""<BR>... for a in range (2,n):<BR>... for x in range (2,a):<BR>... 
  if a % x != 0 :<BR>... print a<BR>...<BR>and then when I type prime(10) or any 
  other number python gives wrong result.What is the right command?<BR><BR>My 
  second question is when I achieve to create a definition for that how can i 
  save it into a file so that the programme will just do this.I mean how to save 
  something you do to an exe file or something similar...(I don't know the logic 
  of python clearly yet)</FONT><BR></DIV>
  <P>
  <HR SIZE=1>
  Do you Yahoo!?<BR><A 
  href="http://us.rd.yahoo.com/mail_us/taglines/10/*http://promotions.yahoo.com/new_mail/static/efficiency.html">New 
  and Improved Yahoo! Mail</A> - Send 10MB messages!
  <P>
  <HR>

  <P></P>_______________________________________________<BR>Tutor maillist&nbsp; 
  -&nbsp; 
Tutor@python.org<BR>http://mail.python.org/mailman/listinfo/tutor<BR></BLOCKQUOTE></BODY></HTML>