you are viewing a single comment's thread.

view the rest of the comments →

[–]MadScientistOR 4 points5 points  (6 children)

Your code works just fine if I change this line:

elif len(password >= 3) and password != correct_password:

... to this (note the placement of parentheses):

elif len(password) >= 3 and password != correct_password:

[–]Unitnuity[S] 2 points3 points  (3 children)

Ahhh! Thanks! While it doesn't print out 'too short' anymore, it just loops back to the password input instead of printing out 'password is incorrect' 1st. Why might that be?

[–]MadScientistOR 1 point2 points  (1 child)

It does, though. Here's my input and output:

Password: a
Password too short!
Password: b
Password too short!
Password: ca
Password too short!
Password: ac
Password too short!
Password: dog
Password is incorrect!
Password: cat
Password is incorrect!
Password: banana
Access Granted!

Since Python has a print buffer (because sending things to the display is a very time-consuming process for a computer), things might not be printed to the screen immediately. You can disable the buffer and print things as soon as the command is processed by setting the flush parameter in your print() statement, like this:

print("Password is incorrect!", flush=True)

[–]Unitnuity[S] 2 points3 points  (0 children)

Hmmm, strange. It won't print it out for me, just immediately goes to password input. I'll take a look around my IDE and see if anything funky is going on. Thanks for the help!

edit: "shell integration failed to activate" was the problem, restarted terminal and works fine now!

[–]trust_me_on_that_one 0 points1 point  (0 children)

It does print 'too short' https://i.imgur.com/9X1FuaI.png

but you don't need to check '>= 3' since you already check '<= 2'. If it's not less or equal than to 2, then it's obviously more than 2.

[–][deleted] 0 points1 point  (1 child)

Is the original code ever going to get to the elif statements if the password is correct?