[Tutor] A problem

Ali Polatel alipolatel at yahoo.com
Sun Jun 27 12:57:38 EDT 2004

 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 :
>>> for n in range(2, 10):
... for x in range(2, n):
... if n % x == 0:
... print n, 'equals', x, '*', n/x
... break
... else:
... # loop fell through without finding a factor
... print n, 'is a prime number'
This lists the prime numbers up to 10 but when I try to create a definition with:
>>> def prime(n) :
... """ Hey dirty python! Show me the prime numbers!! """
... for a in range (2,n):
... for x in range (2,a):
... if a % x != 0 :
... print a
and then when I type prime(10) or any other number python gives wrong result.What is the right command?

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)

Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040627/2214b312/attachment.html

More information about the Tutor mailing list