#Python dict()製作menu
dic = {}
def add():
print(“Input key: “,end=””)
k = eval(input())
print(“Input value: “,end=””)
v=input()
if k not in dic : dic[k] = v
else: print(“The key is already existed”)
def delete():
print(“Input key: “,end=””)
k = eval(input())
if k in dic :
dic.pop(k)
print(str(k) + ” has been deleted”)
else : print(“The key is not found”)
def query():
print(“Input key: “,end=””)
k = eval(input())
if k in dic : print(dic.get(k))
else : print(“The key is not found”)
def display():
for key in dic:
print( str(key)+”:” +str(dic[key]))
def menu():
print()
print(“1: add”)
print(“2: delete”)
print(“3: query”)
print(“4: display”)
print(“5: exit”)
print(“Which one: “,end=” “)
def main():
while True:
menu()
choice = eval(input())
if choice == 1 : add()
elif choice == 2 : delete()
elif choice == 3 : query()
elif choice == 4 : display()
elif choice == 5 : break
else: print(“Try again”)
main()