Python Forum
Experiencing a bug probably related to input() issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Experiencing a bug probably related to input() issue
#1
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!
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.
Reply
#2
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).
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Big Grin Newbie to Python - input and branching issue Sherine 3 2,190 Jul-31-2021, 01:09 AM
Last Post: Pedroski55
  Although this is a talib related Q it's mostly related to python module installing.. Evalias123 4 5,584 Jan-10-2021, 11:39 PM
Last Post: Evalias123
  Mixed string,Integer input variable issue maderdash 2 2,714 Nov-06-2018, 09:46 AM
Last Post: snippsat
  [split] Is there any issue related to path defined somewhere purnima1 2 2,394 Sep-05-2018, 06:28 AM
Last Post: purnima1
  input issue elif jge047 2 3,133 Nov-23-2017, 06:29 AM
Last Post: zykbee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020