Re: [Tutor] Problem with while loop

2007-09-10 Thread Michael Connors
Hi, I would do it as follows, adding 0s to front to make them valid PINs. while counter < howmany: pin = randint(,) print "%04i" % (pin) counter += 1 On 10/09/2007, Vishnu Mohan <[EMAIL PROTECTED]> wrote: > > > > Now I just need to figure out how to only get 4 digit pin numbe

Re: [Tutor] Problem with while loop

2007-09-10 Thread Vishnu Mohan
> Now I just need to figure out how to only get 4 digit pin numbers :) > Use regular expressions The following is the code with re. from random import randint import re counter = 0 pinPattern = re.compile(r'^\d{4}$') howmany = raw_input( "How many: " ) if pinPattern.match(howmany): whil

Re: [Tutor] Problem with while loop

2007-09-07 Thread Ricardo Aráoz
matte wrote: > Hi guys > > Please excuse me but I've been out of Python for a while since my laptop > was stolen... > > I'm battling with a very basic while loop > > -- 8< -- > #!/usr/bin/python > > from random import randint > > counter = 0 > > howmany = r

Re: [Tutor] Problem with while loop

2007-09-07 Thread Michael Connors
You could use string formatting to output all pin numbers as 4 character strings. http://docs.python.org/lib/typesseq-strings.html On 07/09/2007, matte <[EMAIL PROTECTED]> wrote: > > Perfect... > > Thanks very much for your help... > > On 9/7/07, Michael Connors <[EMAIL PROTECTED]> wrote: > > > >

Re: [Tutor] Problem with while loop

2007-09-07 Thread matte
Perfect... Thanks very much for your help... On 9/7/07, Michael Connors <[EMAIL PROTECTED]> wrote: > > I think it will work if you cast your input to an int: > howmany = int(raw_input( "How many: " )) Now I just need to figure out how to only get 4 digit pin numbers :) -m _

Re: [Tutor] Problem with while loop

2007-09-07 Thread Michael Connors
I think it will work if you cast your input to an int: howmany = int(raw_input( "How many: " )) On 07/09/2007, matte <[EMAIL PROTECTED]> wrote: > > Hi guys > > Please excuse me but I've been out of Python for a while since my laptop > was stolen... > > I'm battling with a very basic while loop