[Tutor] New to programming-Help
Alan Gauld
alan.gauld at blueyonder.co.uk
Sat May 22 03:21:20 EDT 2004
> As the book goes on it also talks about elif, and while
> loops. ...
> that the user gets only three attempts to enter the correct
> password = raw input("Enter your Password: ")
> count = 0
>
> while password != "secret":
> print password = raw-input("Enter your Password: ")
> count += 1
The while loop will repeat *the indented block* until the
condition is false. You are only repeating these 2 lines!
However there is another problem further down:
> 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.")
Even if you move these into the loop you are not exiting the loop
after 3 times you only print a message. So your loop test needs
to check for two conditions:
1) The password is not "secret"
2) count is less than 3
Finally think about the value of count. You start it at 0
but test for "count > 3" - how many loops will it take for
count to be greater than 3?
Given that information try modifying your program and see how you get
on.
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list