Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Passwords
#11
That's because you're missing a colon at the end of line 7.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#12
(Sep-22-2019, 01:57 AM)ichabod801 Wrote: That's because you're missing a colon at the end of line 7.

if password in thisdict.values: 
like this? It works but I also get an error

if password in thisdict.values:
TypeError: argument of type 'builtin_function_or_method' is not iterable
Reply
#13
Now you miss () (you had them previously)
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
#14
if
if password in thisdict.values()
shows error
Reply
#15
And now you miss colon again. You must have both.
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
#16
you really need to pay more attention and be able to debug such errors on your own
if password in thisdict.values():
Even if it works, it's a valid question as to why you use a dict at all... It doesn't make sense to use a dict in this case
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#17
Best excuse for using a dictionary for this is if you are taking the next step and doing a username password combination. This is not the assignment so I don't think I violate rules by posting the code, but here:
import getpass
username = input("Input user name: ")
password = getpass.getpass("Password: ")
thisdict = {
  "sport": "football",
  "drink": "sprite",
  "food": "pizza",
    "woodrow": "roosevelt"
}
if username in thisdict:
    if thisdict.get(username) == password :
        print(f"Welcome {username}")
        #playgame()
    else:
        print(f"Oops {username}, can't find your username/password")
else:
    print(f"Oops {username}, can't find your username/password")
By using getpass, the password is entered as a row of stars. It then finds if username is in the dictionary, then checks to see if the password matches (you don't want to approve if the user name and password are in the dictionary but are not linked). You also want to give the same error message if the username is not found or if it is and the password doesn't match. Also note that the username and password are case sensitive.
Reply
#18
remove the line 9.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Hashing Passwords (HELP) MianDoesCoding 4 2,129 May-26-2020, 03:11 PM
Last Post: buran
  Writing incorrect passwords to a file till its correct garth 2 4,901 Feb-10-2017, 11:41 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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