Python Newbie

Larry Bates lbates at swamisoft.com
Fri May 21 19:24:12 EDT 2004


As Jorge points out, indentation matters.  Try
something like:

import sys
count=0
while 1:
    password = raw_input("Enter your Password (blank to exit): ")
    count += 1

    if password == "secret":
        print "Welcome in."
        break

    elif not password:        sys.exit()

    else:
        if count < 3:
            print "Wrong password"
            continue
        else:
            print "Please come back when you remember your Password."
            sys.exit()


>
> Ok, I know I may be way off course here but any help would be greatly
> appreciated.  I dont want to get frustrated and say the heck with it,
> especially if it is something minor.  Thanks in advance.

"Brian" <blugerz at yahoo.com> wrote in message
news:3c0a04e4.0405211434.6667f727 at posting.google.com...
> Hi I am new to this newsgroup and new to programming.  I have had this
> interest in learning to program because.......well just because.  It's
> just a curiosity that I have.  The reason I am starting with Python,
> well some of the websites I went to recommended Python, so here I am.
> Ok on to the question.
>
> I am currently using the book "Python programming for absolute
> beginners" by Michael Dawson.  The program I am working on is a
> password program....dont laugh I know it's really simple to some, but
> I am kinda stuck.  The book shows how to code a password program like
> this:
>
> password = raw_input("Enter your password:")
>
> if password == "secret":
>      print "Access Granted"
> else:
>      print "Access Denied"
>
> raw_input("Press the enter key to exit")
>
> Ok that is easy enough I understand what is going on here.  As the
> book goes on it also talks about elif, and while loops.  At the end of
> the chapter it gives various challenges that the reader is asked to
> complete.  One of the challenges is to take the password program from
> above and change it so that the user gets only three attempts to enter
> the correct password.  Well I ain't got it to work yet, I thought I
> came close, but no cigar.  This is what I have so far:
> #Limiting password atempts to three
>
> password = raw_input("Enter your Password: ")
> count = 0
>
>
> while password != "secret":
>      print password = raw-input("Enter your Password: ")
>      count += 1
>
> if password == "secret":
>      print "Welcome in."
>
>
> elif count > 3:
>      print "Please come back when you remember your Password."
>
> else:
>      raw_input("Press enter to exit.")
>
> Ok, I know I may be way off course here but any help would be greatly
> appreciated.  I dont want to get frustrated and say the heck with it,
> especially if it is something minor.  Thanks in advance.





More information about the Python-list mailing list