Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 adding information to a dictionary.
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":
    elif status == "n":
    elif status == "!":

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

    if createAccount in users:
        print("\nUsername already taken.\n")
        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")
        print("\nError: invalid username or password and/or invalid combination.")

while status != "!":


*John:Doe and GEO:Rock are key value's that I put in just to test its ability to save an account.
Looks like the new login and password is added to the dictionary on line 20. is it not working for you?
So it adds it but only when the program is running. So after you create an account, you can then login and it will print "login successful" but as soon as you exit, you can't re-run it and login because it hasn't saved the credentials.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 136 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  Adding markers to Folium map only adding last element. tantony 0 161 Oct-16-2019, 03:28 PM
Last Post: tantony

Forum Jump:

Users browsing this thread: 1 Guest(s)