[Tutor] Thanks-finally got it to work
alan.gauld at blueyonder.co.uk
Mon May 24 12:51:12 EDT 2004
> Thanks for everyones help I finally got it to work:
Are you sure?
What this does is tries 3 times to get a password
- any password not just the right one.
> #Limiting password atempts to three
> count = 1
> password = ""
> while not password and count < 3:
> password = raw_input("Please enter your Password:
> count += 1
> if password == "secret":
> print "Welcome in."
> elif raw_input("Please enter your Password: "):
> count += 1
And incrementing count here has no effect whatsoever
because you are now outside the while loop.
> count == 3
And this line just evaluates to a boolean value but
is not used.
> print "Try again later when you remember your
> raw_input("Press enter to exit.")
> It may not be the perfect way, but it is finally doing
> what I want it to.
You may be right, but I wonder if you have actually tested
For example try these scenarios and see if they do what you expect:
1) Run the program and hit return with no password everytime.
2) Run the program but using the wrong value the first time.
3) Run the program and use the wrong value twice
4) Run the program and use the wrong value three times
5) Run the program and use the wrong value four times(!)
6) Run the program and use the right value first time.
If they all do what you expect, congratulations, it's just
your interpretation of the requirements were different to
mine. If not its time to pull the thinking cap back on. :-)
More information about the Tutor