简体   繁体   中英

print the output It don`t show anything

I made a dictionary in IDE and made a function to take input from user and it takes the input but when I rerun that program and try to print the output It don`t show anything. Here is the code, help if anyone want to.

# Created dictionary.

list = {}

# Made a Function to save data.

def up():
    v = int(input(f"How many inputs you want to give : "))

    for i in range(v):
        a = input(f"Give words you want to put : ")
        b = input(f"Assign : ")
        list.update({a:b})
    print(f"Saved",{a:b})


value = input(f"What you want to do ? \nSee List or update it. \nIf you want to update type 'u' , If you want to see list type 's' ")


if value == "s":
    print(list)
elif value == "u":
    up()

Information in your variables is stored during the execution of your script. It is not automatically carried across to different executions of your script. Each one is a blank slate. Even if it weren't, the first line of your program sets list to an empty dictionary.

At the moment, you're putting salt on your broccoli, eating it, then expecting the broccoli you eat tomorrow to also have salt on it.

You could serialise the dictionary to a file, that can be read back in on next execution, rather than starting with an empty dictionary each time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM