Python Forum
adding information to a dictionary.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
adding information to a dictionary.
#1
So I'm creating a basic program where when it is run it asks the user if they have an account. If they enter "n" (no) then they are prompted to create a username and password. If they enter "y" they can login. the issue is that the username and password is only stored as key:value while the program is running, and is forgotten as soon as it is exited. If I manually enter into the dictionary a key:value then it is saved as an account and I can login to it. I'm trying to make it so that the account created when the user signs up is automatically put into the dictionary. Here is what I have:
users = {"John":"Doe", "GEO":"Rock"}
status = ""

def mainDisplay():
    status = input("Do you have an account?: y/n? Press ! to quit: ")
    if status == "y":
        existUser()
    elif status == "n":
        newUser()
    elif status == "!":
        quit()

def newUser():
    createAccount = input("Please create a username: ")

    if createAccount in users:
        print("\nUsername already taken.\n")
    else:
        createPass = input("Create a password")
        users[createAccount] = createPass
        print("\nUser created\n")

def existUser():
    login = input("Enter your username: ")
    passw = input("Enter your password: ")

    if login in users and users[login] == passw:
        print("\nLogin successful.\n")
    else:
        print("\nError: invalid username or password and/or invalid combination.")

while status != "!":
    mainDisplay()
Thanks


*John:Doe and GEO:Rock are key value's that I put in just to test its ability to save an account.
Reply


Messages In This Thread
adding information to a dictionary. - by Justice_py - Dec-05-2019, 02:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding to the dictionary inside the for-loop - weird behaviour InputOutput007 5 2,758 Jan-21-2021, 02:21 PM
Last Post: InputOutput007
  Adding keys and values to a dictionary giladal 3 2,536 Nov-19-2020, 04:58 PM
Last Post: deanhystad
  Pulling Information Out of Dictionary Griever 4 2,928 Aug-12-2020, 02:34 PM
Last Post: Griever
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,069 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  Adding markers to Folium map only adding last element. tantony 0 2,146 Oct-16-2019, 03:28 PM
Last Post: tantony

Forum Jump:

User Panel Messages

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