Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3602198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:42:58+00:00 2026-05-18T20:42:58+00:00

So basically im new to python and programming in general. I was wondering say

  • 0

So basically im new to python and programming in general. I was wondering say you have a situation where you have a dictionary and are asking the user if they want to add or delete terms in the dictionary. So I know how to add or delete the term in dictionaries but how do “save” that data for the next time the program starts. Basically, if the user added a word to the dictionary and then I asked them if they wanted to return to the main menu using a while loop, how would you make it so the word they added is now permanently in the dictionary when he returns to the menu and starts the program over?

Here is what I had. Mind you I’m a beginner and so if it looks weird, then sorry…lol….nothing serious:

loop=None
while True:
    #The initial dictionary
    things={"house":"a place where you live",
            "computer":"you use to do lots of stuff",
            "iPod":"mp3 player",
            "TV":"watch shows on it",
            "bed":"where you sleep",
            "wii":"a game system",
            "pizza":"food"}


    #Menu
    print("""

        Welcome to the Dictionary of Things
            Choose your preference:

        0-Quit
        1-Look up a Term
        2-Add a Term
        3-Redefine a Term
        4-Delete a Term

        """)

    choice=input("\nWhat do you want to do?: ")

elif choice=="2": #Adds a term for the user
        term=input("What term do you want to add? ")
        if term not in things:
            definition=input("Whats the definition? ")
            things[term]=definition #adds the term to the dictionary
            print(term,"has been added to the dictionary")
            menu=input("""
                    Would you like to go back to the menu?
                            Yes(Y) or No(N):  """)
                if menu=="Y":
                    loop=None  ----->#Ok so if they want to go back to the menu the program should remember what they added
                elif menu=="N":
                    break
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:42:58+00:00Added an answer on May 18, 2026 at 8:42 pm

    Update:

    Your problem is that you redefine the dictionary at the start of each loop. Move the start definition of the dictionary to before the While loop, and you are in business.


    Dictionaries and lists are mutable objects. Hence, if it is modified in a function, it stays modified where it was called too:

    def main_function():
        do someting
        mydict = {'a': 2, 'b': 3}
        subfunction(mydict)
        print mydict
    
    def otherfunction(thedict):
        dict['c'] = 5
    

    If you now run main_function, it will print out a dictionary that includes ‘c’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.