Python Forum

Full Version: Experiencing a bug probably related to input() issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everybody. I am learning Python from the book "Automate boring stuff with python". There is the following code which should have ended up with "Access granted." when right password entered:
while True:
print('Who are you?')
name = input()
➊ if name != 'Joe':
➋ continue
print('Hello, Joe. What is the password? (It is a fish.)')
➌ password = input()
if password == 'swordfish':
➍ break
➎ print('Access granted.')

In my case however it ends up as following when I enter the password "swordfish:
Who are you?
Bob
Who are you?
Joe
Hello, Joe.What is the password?(It is a fish.)
swordfish
>>>

I checked punctuation and found out that it is something to do with input(). Because when I entered Joe for the password program did two things at the same time: It wrote "Access granted" and "Who are you?". The book, however, claims that it should work Ok with "swordfish" (which is not happening). Who can let me know what is the bug here? Thanks in advance!
As you code in not in code tags it is impossible to figure out indentation but based on your description I suspect that you have 'Access granted' wrongly indented (i.e. inside while-loop).