Exercise:
print("English-Chinese Dictionary")
d = dict()#create an empty dictionary
while True:
num = input("Please pick an operation:"\
"\n1.Add Item\n2.Search Item\n3.Delete Item\n4.Update Item"\
"\n5.View All Keys\n6.View All Keys and Explanations\n7.Quit\n")
if num == "7":
print("Abort System")
break
elif num == "1":
word = input("Please input the word:")
exp = input("Please input the explanations of the "+word+":")
d[word] = exp
elif num == "2":
word = input("Please input the word you look for:")
if word in d:
print(d.get(word))
else:
print(word+" does not exist.")
elif num == "3":
word = input("Please input the word to be deleted:")
if word in d:
del(d[word])
else:
print(word + " does not exist.")
elif num == "4":
word = input("Please input the word to be updated:")
if word in d:
exp = input("Please update "+word+"'s explanations:")
d[word] = exp
else:
print(word + " does not exist.")
elif num == "5":
for i in d.keys():
print(i)
elif num == "6":
for i in d.items():
for j in i:
print(j,end = " ")
print()#output a new line
[…] 2)| |____Unit 39 Tuple| |____Unit 40 Dictionaries| |____Unit 41 English-Chinese Dictionary| |____Unit 42 String Operations|____Python Level 5| |____Unit 43 Getting to know functions for the first time| |____Unit 44 […]