[Tutor] password loop
steve at pearwood.info
Sat Sep 24 04:17:30 CEST 2011
ADRIAN KELLY wrote:
> Can anyone help me with the programme below; i hope you can see what i am trying to do, if i enter the wrong password the loop goes on forever and if i enter the right one nothing is printed...
> i am a newbie............all comments welcome
> thanks adrian................
> print 'hello'
> print 'i am your computer'
> # set the values
> Enter_Password=raw_input ('please enter your password: ')
This sets the password once, outside the loop.
> #password loop
> while Enter_Password != password:
> if Enter_Password !=password:
> print 'try again'
> print 'well done'
This loops forever, but never asks for a password. You need to ask for a
password *inside* the loop.
actual_password = 'route9999'
given_password = ''
while given_password != actual_password:
given_password = raw_input('please enter your password: ')
if given_password == actual_password:
print 'well done'
print 'try again'
More information about the Tutor