[Tutor] Problem with while loop

Vishnu Mohan vishnu at montalvosystems.com
Mon Sep 10 12:40:46 CEST 2007


> 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):
    while counter < int(howmany):
        pin = randint(0000,9999)
        print pin
        counter += 1
else:
    print "%s is not valid 4 digit integer"%howmany


-vishnuMohan


More information about the Tutor mailing list