Click to See Complete Forum and Search --> : syntax error python


chris65
07-14-2002, 03:57 AM
password = "foobar"
while password != "unicorn":
password = raw_input ("password:")
print "welcome in"

this is simple i know, but this is what i am trying to do. Just learning python.

different from above:

password = "foobar"
guess = 3
while password != "unicorn":
password = raw_input ("password:")
#gets input for password, now if input is given more that 3
#times then warning
if guess > 3:
print "To Hard?"
else:
print "welcome in"

"or" if raw_input > 3

there are a few way's that jump out but none of them are right. The manual has an example but i tried it in this one and its no good. Help??

EscapeCharacter
07-14-2002, 04:23 AM
what exactly is the syntax error you are getting?

chris65
07-14-2002, 05:42 AM
ok, i fixed the syntax error. I missed a colan at end of the else statement. now the program runs with out stoping to see if the password is legal. It prints "welcome in" no matter what you put in the blank. I guess you say i got a format problem now. I know its in the if statement (pretty sure) and cant get it right. Would i get the info i need from the raw_input part of the script, or from the guess = 3 part like i have above.
I am really not sure which one will give me the info for the "if " statement. I dont see why its not working, but i just started with python so am not ready to guess that far out yet.

EscapeCharacter
07-15-2002, 12:35 AM
this should do what you are asking for

import sys
password = "blah"
count = 0
while password != "liam":
password = raw_input("Password:")
count = count + 1
print count
if count > 3:
print 'you are out of luck'
sys.exit(1)
print "welcome"
raw_input()

chris65
07-15-2002, 05:47 AM
Thank you again. God i knew it had to be easy but could not find "count" anywhere. (sigh) now i can die happy. :D

inkedmn
07-15-2002, 02:12 PM
you might also want to look at the getpass module. it's used to get password input, but it doesn't echo back what the user is typing.

like this:

password = getpass.getpass("Password: ")


it's pretty cool...