help on ultra newbie program please

cybernut cybernut at uswest.net
Wed May 21 19:13:28 EDT 2003


"phil hunt" <philh at cabalamat.org> wrote in message
news:slrnbcnsgf.rm.philh at cabalamat.uklinux.net...
> On Wed, 21 May 2003 10:30:06 -0600, cybernut <cybernut at uswest.net> wrote:
> >I'm a network admin, but have had an itch to learn programming for a
while
> >and finally started looking at which language to begin with. After
reading
> >for a while it sounded like python was a really good one so I went to
> >www.python.org and started going through the "A Non-Programmer's Tutorial
> >for Python" guide by Josh Cogliati. I already have a linux box running
that
> >I am using for this...
> >
> >I'm kind of stuck on one of the excersizes though and I hate to ask for
help
> >on this because I want to figure it out on my own, but I've wasted too
much
> >time on it. It is basically taking his Password.py code and modifying it
so
> >that it kicks you out if an incorrect password is entered 3 times. Now, I
> >can get it to kick ya out if 3 bad passwords are entered ,but I cannot
get
> >it to do that and also end it if the correct password is put in. It will
> >take the correct password and ask for another password again which is
> >stupid. It seems like I need a loop within a loop, but Im not seeing it.
> >Anyone able to shed some light on this for me? Maybe Im not cut out for
> >this, but I wanna give it a good go.
>
> Use this pseudocode:
>
>    password := "whatever"
>    tries := 0
>    userIn := false #user is in the system?
>    loop forever:
>       entry := getUsersEntry()
>       tries := tries + 1
>       if entry == password:
>          print "You are in!"
>          userIn := true
>          exit loop
>       if tries >= 3:
>          print "You entered 3 bad entries"
>          exit loop
>
> In Python this is:
>
>    password = "whatever"
>    tries = 0
>    userIn = 0 #user is in the system?
>    while 1:
>       entry = raw_input("Enter Password:")
>       tries = tries + 1
>       if entry == password:
>          print "You are in!"
>          userIn = 1
>          break
>       if tries >= 3:
>          print "You entered 3 bad entries"
>          break
>
> Note the similarities between Python and pseudocode!
>
> (BTW, I'm not sure which version of Python you are using; on later
> versions you can say things like:
>
>    userIn = true
>
> and:
>
>    tries += 1
>
> -- 
> Philip Hunt <philh at cabalamat.org>
>
> Interested in adventure holidays in Spain?
> Look at: <http://www.cabalamat.org/advcon/>

Philip,

That is interesting how similar they are. Ive never heard of pseudocode, but
I'm just starting out in the world of programming. Btw, I am using python
2.2.2 and tries += 1 did work in the program I was working on. Thanks for
your input and example!!






More information about the Python-list mailing list