d = {"FCC":"北美","CE":"歐盟"}
def f():
for i in d:
i = input("請輸入你要查詢的國家碼:\n>>>")
if i in d:
print("查詢結果為:",d[i])
f()
if i not in d:
a = input("""抱歉,您查詢的國家碼未在字典內;\b
1.添加請輸入:"add";
2.列印字典內容請輸入:"all";
3.回傳查詢請按任意鍵;
4.退出程式請輸入:"exit";
>>>""")
if a == "add":
x = input("添加的國家碼字母為:")
y = input("添加的國家碼注釋為:")
d[x] = y
f()
elif a == "all":
print("當前字典全部內容如下:",d)
f()
elif a == "exit":
return
f()
uj5u.com熱心網友回復:
補充:想著雙擊檔案打開.py 添加字典后能寫到py檔案里去,下次打開能查得到轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/243683.html
上一篇:python
