while True:
print("HI , TELL YOUR NAME")
name = input()
if name != 'anwar':
continue
print("your password , please")
password=input()
if password != 'bull':
break
print("access granted")
So the problem here is when I receive the output, I get the first print statement's string that is
---------------output-------------
HI , TELL YOUR NAME
anwar
your password , please
bull
access granted
HI , TELL YOUR NAME
I dont want the first statement to printed again..
where as I look into my book and I saw that the same program prints perfectly ..
Python 3.6
1 while True:
2 print('Who are you?')
3 name = input()
4 if name != 'Joe':
5 continue
6 print('Hello, Joe. What is the password? (It is a fish.)')
7 password = input()
8 if password == 'swordfish':
9 break
10 print('Access granted.')
and the output is what I want really wanted ........
--------------output----------
Who are you?
Joe
Hello, Joe. What is the password? (It is a fish.)
swordfish
Access granted.
please note that the first statment "who are you?" doesn’t print at the end of the program.
The correct code is breaking on the right password, while you are breaking if the password doesn't match. So the it will keep looping until you enter a wrong password
should be
to break the loop on bull