Re: [Tutor] Prime numbers

2010-03-28 Thread Rafik Ouerchefani
On Sat, Mar 27, 2010 at 11:08 PM, yd wrote: > > Having a problem finding the first 1000 prime numbers, here is my code:- > > print(2) > n =3 > counter =1 > while counter <=1000: >   for x in range(3,int((n**0.5)),2): >     if n%x != 0: >   print(n) >   n+=1 >   counter+=1 >     else: >

Re: [Tutor] return first line

2010-03-15 Thread Rafik Ouerchefani
Hi, assuming that your content is in input.txt, you can do : >>> f = open("/path/to/content.txt") >>> f.readline() it will return the first line only cheers, - Rafik ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription option

[Tutor] split a 5 chars word into 4 and 1

2010-03-09 Thread Rafik Ouerchefani
Hello, I'm trying to split 5 chars words (codes) into 2 variables. The first must contain the first 4 characters. The second variable will only contain the last character. I'm working in a loop pre-generated codes. Any magic command for this ? :-) Examples of codes : 3cmvA 3cmvB 3cmvC 3cmwA 1g18