Python Forum
Experiencing a bug probably related to input() issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Experiencing a bug probably related to input() issue (/thread-31338.html)



Experiencing a bug probably related to input() issue - NewtoPython2020 - Dec-05-2020

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!


RE: Experiencing a bug probably related to input() issue - perfringo - Dec-05-2020

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).