Python Newbie

EAS eriksp at attbi.nospam.com
Fri May 21 19:07:51 EDT 2004


Hey, I'm using the same book! : )

I'm a newbie too, but I think I can still help you.
Let's take a look at your code:

#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.")

The first error I spot is in the loop - "raw-input" should be "raw_input".
"elif count"
should be == 3, not more than 3. Also, you do not need "print" before
"password".
If you want to view one of the messages before it closes out, you must take
the last
statement out of "else" and make it its own. Otherwise, it won't run that
statement.

The rest is just the structure of the program... according to the loop, the
user
must enter passwords until he/she types in the word "password", where the
statement
password != "secret" becomes false. Only then will the program move onto the
"if"
statement and tell the user whether they are granted access or not. To end
the loop
when the user guesses 3 times, you need to add another "if" statement inside
the loop
that breaks it if the count is equal to 3. Here is the new program:

#Limiting password atempts to three

password = raw_input("Enter your Password: ")
count = 0


while password != "secret":
     if count == 3:
           break
     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.")

Remember to go step by step through the program when you have errors
and see exactly what it does.






More information about the Python-list mailing list