標籤:.com app ack 刪除使用者 ima dea phone img dict
首先建立項目,包含主程式cards_main和工具庫cards_tools:
如下:
main函數主主要使用while和if實現4功能切換,切換的具體操作由cards_tools中的函數執行。不說了直接上代碼,代碼都比較簡單:
(1)cards_main:
* coding : UTF-8
*
"""
File_name : cards_main.py
Author : jack
Date : 2018.7.18
Function : 名片管理系統主程式
"""
import cards_tools
使用while實現視窗的迴圈使用
while True:
?? cards_tools.cards_dis()
?? cards_input = input("請選擇操作功能:")
?? if cards_input in ["1", "2", "3"]:
????? if cards_input == "1":
???????? print("- " 20)
???????? print("您選擇輸入的作業碼是: 1" )
???????? cards_tools.cards_add()
????? elif cards_input == "2":
???????? print("- " 20)
???????? print("您選擇輸入的作業碼是: 2" )
???????? cards_tools.cards_show_all()
????? elif cards_input == "3":
???????? print("- " 20)
???????? print("您選擇輸入的作業碼是: 3" )
???????? cards_tools.cards_requ()
?? elif cards_input == "0":
????? print("您選擇輸入的作業碼是: 0" )
????? print("即將退出系統......\n" "已退出系統,歡迎您下次【名片管理系統】!")
????? break
?? else:
????? cards_input = input("輸入錯誤,請重新輸入:")
????? cards_tools.cards_dis()
????? #cards_input = input("輸入錯誤,請重新輸入:")
????? while True:
???????? cards_input = input("輸入錯誤,請重新輸入:")
???????? cards_tools.cards_dis()
???????? if cards_input in ["1", "2", "3", "0"]:
??????????? if cards_input == "1":
?????????????? print("- " 20)
?????????????? print("您選擇輸入的作業碼是: 1")
?????????????? cards_tools.cards_add()
?????????????? break
??????????? if cards_input == "2":
?????????????? print("- " 20)
?????????????? print("您選擇輸入的作業碼是: 2")
?????????????? cards_tools.cards_show_all()
?????????????? break
??????????? if cards_input == "3":
?????????????? print("- " 20)
?????????????? print("您選擇輸入的作業碼是: 3")
?????????????? cards_tools.cards_requ()
?????????????? break
??????????? else:
??????????? # #print("返回主菜單")
?????????????? break
????? break
(2)cards_tools:
* coding : UTF-8
*
"""
File_name : cards_main.py
Author : jack
Date : 2018.7.18
Function : 名片管理系統tools
"""
顯示菜單
def cards_dis():
?? """顯示菜單"""
?? print(" " 20)
?? print("\t歡迎使用【名片管理系統 V1.0】\n"
????? "\t\t\t1. 建立名片\n" "\t\t\t2. 顯示全部\n" "\t\t\t3. 查詢名片\n\n" "\t\t\t0. 退出系統")
?? print(" " 20)
cards_list = []
新增名片
def cards_add ():
?? """新增名片"""
?? print("- " * 20 )
?? print("新增名片")
?? """輸入-整理成字典-將字典儲存到列表中-提示輸入成功"""
?? name_str = input("請輸入姓名:")
?? gender_str = input("請輸入性別:")
?? tel_int = input("請輸入電話:")
?? add_str = input("請輸入地址:")
?? cards_dict = {"name" : name_str,
????????????? "gender" : gender_str,
????????????? "telephone" : tel_int,
????????????? "address" : add_str}
?? cards_list.append(cards_dict)
?? print(cards_list)
?? print("%s 的名片新增成功!" % name_str)
顯示全部
def cards_show_all ():
?? """顯示全部名片"""
?? print("- " 20)
?? print("顯示所有名片")
?? if len(cards_list) == 0:
????? print("當前系統中沒有名片,請新增名片!")
?? else:
????? print("=" 40)
????? #print("姓名\t\t" "性別\t\t" "電話\t\t" "地址")
????? for name in ("姓名","性別","電話","地址"):
???????? print(name, end="\t\t")
????? print(" ")
????? for cards_dict in cards_list:
???????? print("%s\t\t%s\t\t%s\t\t%s" % (cards_dict["name"],
???????????????????????????????? cards_dict["gender"],
???????????????????????????????? cards_dict["telephone"],
???????????????????????????????? cards_dict["address"]))
???????? print(cards_dict)
????? print("=" * 40)
查詢名片
def cards_requ ():
?? """查詢名片"""
?? print("- " 20)
?? print("查詢名片")
?? find_name = input("請輸入要搜尋的姓名:")
?? if len(cards_list) == 0:
????? print("抱歉!沒找到使用者 %s 的資訊, 請新增!" % find_name)
?? else:
????? for search_name in cards_list:
???????? if search_name["name"] == find_name:
??????????? print("找到 %s 的資訊了。" % find_name)
??????????? print("=" 40)
??????????? for name in ("姓名", "性別", "電話", "地址"):
?????????????? print(name, end="\t\t")
??????????? print(" ")
??????????? print("s%\t\ts%\t\ts%\t\ts%" % (search_name["name"],
??????????????????????????????????? search_name["gender"],
??????????????????????????????????? search_name["telephone"],
??????????????????????????????????? search_name["address"]))
??????????? print("=" * 40)
??????????? cards_deal(search_name)
??????????? break
???????? else:
??????????? print("抱歉!沒找到使用者 %s 的資訊。" % find_name)
刪除和修改名片資訊
def cards_deal(find_dict):
?? """修改和刪除名片"""
?? deal_cards = input("請選擇要進行的操作: [1] 刪除\t\t[2] 修改\t\t[3] 返回主菜單\n")
?? if deal_cards in ["1","2","3"]:
????? if deal_cards == "1":
???????? cards_list.remove(find_dict)
???????? print("刪除使用者 %s 名片成功!" % (find_dict["name"]))
????? if deal_cards == "2":
???????? find_dict["name"] = cards_mod(find_dict["name"], "請輸入修改後的姓名:")
???????? find_dict["gender"] = cards_mod(find_dict["gender"], "請輸入修改後的性別:")
???????? find_dict["telephone"] = cards_mod(find_dict["telephone"], "請輸入修改後的電話:")
???????? find_dict["address"] = cards_mod(find_dict["address"], "請輸入修改後的地址:")
???????? print("使用者 %s 的名片修改成功!" % find_dict["name"])
?? else:
???????? print("輸入錯誤,請重新輸入!")
def cards_mod(cards_value, cards_new):
?? result = input(cards_new)
?? if len(result) > 0:
????? return result
?? else:
????? return cards_value
本人也是新手,歡迎大佬們批評指正。
用Python實現簡單的名片管理系統