名片管理系統(tǒng)python版
本文實(shí)例為大家分享了python名片管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
import os
list_all = []
def page():
"""輸出主頁(yè)面"""
print("*" * 30)
print("歡迎使用[名片管理系統(tǒng)]v2.0")
print()
print("1.新建名片")
print("2.查看全部")
print("3.查詢(xún)名片")
print("4.保存信息")
print()
print("0.退出系統(tǒng)")
print("=" * 30)
def new_cards():
"""接收用戶(hù)輸入的信息保存至字典"""
dict_1 = {"name": input("姓名:"),
"age": input("年齡:"),
"phone": input("電話(huà):"),
"email": input("郵箱:")}
# 將字典添加至列表
list_all.append(dict_1)
def check_all():
"""將所有的字典信息進(jìn)行打印"""
if len(list_all) > 0:
print("姓名\t\t年齡\t\t電話(huà)\t\t郵箱")
for i in list_all:
print("%s\t\t%s\t\t%s\t\t%s" % (i["name"], i["age"],
i["phone"], i["email"]))
else:
print("還沒(méi)有任何信息")
def check_cards():
"""查詢(xún)名片"""
user = input("請(qǐng)輸入要查詢(xún)的姓名:")
for i in list_all: # 遍歷全局列表,將存入的字典依次取出
if i['name'] == user: # 如果字典的值跟用戶(hù)搜索的值相同打印字典
print("姓名\t\t年齡\t\t電話(huà)\t\t郵箱")
print("%s\t\t%s\t\t%s\t\t%s" % (i["name"], i["age"],
i["phone"], i["email"]))
revise_cards(i)
else:
print("沒(méi)有查詢(xún)到您搜索的信息")
def revise_cards(dict_1):
"""修改名片,接收之前已經(jīng)查到的字典"""
while True:
user_choor = input("1.修改名片 2.刪除名片 0.返回主菜單")
if user_choor == "1": # 如果用戶(hù)輸入1執(zhí)行修改功能
print("修改名片,注:修改直接輸入修改內(nèi)容,回車(chē)不修改")
dict_1["name"] = revise(dict_1["name"], input("姓名"))
dict_1["age"] = revise(dict_1["age"], input("年齡"))
dict_1["phone"] = revise(dict_1["phone"], input("電話(huà)"))
dict_1["email"] = revise(dict_1["email"], input("郵箱"))
print("修改成功")
break
# laturn
elif user_choor == "2": # 如果輸入2刪除字典
list_all.remove(dict_1)
print("刪除名片成功")
break
elif user_choor == "0":
break
else:
print("輸入錯(cuò)誤請(qǐng)重新輸入")
def revise(old, new):
"""實(shí)現(xiàn)回車(chē)不修改的功能"""
if len(new) <= 0:
return old
else:
return new
def save_dir():
"""將文件保存至指定文件"""
a = open("123.xlsx", "w")
a.write(str(list_all))
a.close()
print("保存成功")
def read_dir():
"""讀取文件"""
if os.path.exists("123.data"):
a = open("123.data", "r")
b = eval(a.read())
global list_all
list_all = b
a.close()
import cards_tools
# 讀取文件
cards_tools.read_dir()
while True:
cards_tools.page()
user_input = input("請(qǐng)選擇您要執(zhí)行的操作")
if user_input == "1":
print("即將執(zhí)行:新建名片")
cards_tools.new_cards()
elif user_input == "2":
print("即將執(zhí)行:查看全部")
cards_tools.check_all()
elif user_input == "3":
print("即將執(zhí)行:查詢(xún)名片")
cards_tools.check_cards()
elif user_input == "4":
print("即將執(zhí)行:保存信息")
cards_tools.save_dir()
elif user_input == "0":
print("歡迎下次使用[名片管理系統(tǒng)]")
exit()
else:
print("你的輸入有誤,請(qǐng)重新輸入")
更多學(xué)習(xí)資料請(qǐng)關(guān)注專(zhuān)題《管理系統(tǒng)開(kāi)發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 詳解Python做一個(gè)名片管理系統(tǒng)
- python實(shí)現(xiàn)名片管理系統(tǒng)
- python實(shí)現(xiàn)簡(jiǎn)單名片管理系統(tǒng)
- 一個(gè)簡(jiǎn)單的Python名片管理系統(tǒng)
- python3實(shí)現(xiàn)名片管理系統(tǒng)
- python面向?qū)ο髮?shí)現(xiàn)名片管理系統(tǒng)文件版
- 基于python實(shí)現(xiàn)名片管理系統(tǒng)
- Python實(shí)現(xiàn)名片管理系統(tǒng)
- Python版名片管理系統(tǒng)
- python實(shí)現(xiàn)簡(jiǎn)單的名片管理系統(tǒng)
相關(guān)文章
使用Python三角函數(shù)公式計(jì)算三角形的夾角案例
這篇文章主要介紹了使用Python三角函數(shù)公式計(jì)算三角形的夾角案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04
python中torch.load中的map_location參數(shù)使用
在PyTorch中,torch.load()函數(shù)是用于加載保存模型或張量數(shù)據(jù)的重要工具,map_location參數(shù)為我們提供了極大的靈活性,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
python向MySQL數(shù)據(jù)庫(kù)插入數(shù)據(jù)的操作方法
這篇文章主要介紹了python向MySQL數(shù)據(jù)庫(kù)插入數(shù)據(jù),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-11-11
python實(shí)現(xiàn)登錄與注冊(cè)功能
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)登錄與注冊(cè)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
Python字符串str和json格式相互轉(zhuǎn)換
這篇文章主要介紹了Python字符串str和json格式相互轉(zhuǎn)換,str轉(zhuǎn)換為json格式,前提一定需要保證這個(gè)str的格式和json是一致的。下文小編向大家介紹更多相關(guān)內(nèi)容,需要的朋友可以參考一下2022-03-03

