Python dict()製作menu

加入好友
加入社群
Python dict()製作menu - 儲蓄保險王

#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()

Python dict()製作menu - 儲蓄保險王

Python dict()製作menu - 儲蓄保險王

 

加入好友
加入社群
Python dict()製作menu - 儲蓄保險王

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡

You may also like...

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *