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!
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!
buran write Dec-05-2020, 07:34 AM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Don't include line numbers in the code.
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Don't include line numbers in the code.