名片管理系統

2021-09-13 19:16:08 字數 2759 閱讀 1237

#儲存所有名片的列表

cardlist =

def showmenu():

'''顯示功能選單'''

print("*" * 100)

print("歡迎使用【名片管理系統】")

print("1. 新增名片")

print("2. 顯示全部")

print("3. 搜尋名片")

print("\n")

print("0. 退出系統")

print("*" * 100)

def newcard():

'''新增名片'''

print("-" * 100)

print("新增名片")

#提示使用者輸入資訊

name = input("請輸入姓名: ")

#建議乙個名片字典

carddict =

#將名片新增到字典列表中

print(cardlist)

#提示使用者新增成功

print("新增%s的名片成功! " % name)

def showall():

'''顯示所有名片'''

print("-" * 100)

print("顯示所有名片")

#判斷是否存在名片記錄,如果沒有,提示使用者並且返回

if len(cardlist) == 0:

print("當前沒有任何名片記錄,請新增名片!")

return

#列印表頭

for name in ["name", "phone", "qq", "email"]:

print(name, end="\t\t\t")

print("")

# 列印分割線

print("=" * 100)

#遍歷名片列表以此輸出字典資訊

for carddict in cardlist:

print("%s\t\t\t%s\t\t\t%s\t\t\t%s" % (carddict["name"],

carddict["phone"],

carddict["qq"],

carddict["email"]))

def searchcard():

'''搜尋名片'''

print("-" * 100)

print("搜尋名片")

#提示使用者輸入要搜尋的姓名

findname = input("請輸入要搜尋的姓名: ")

#遍歷名片列表,查詢要搜尋的姓名,如果沒有找到,需要提示使用者

for carddict in cardlist:

if carddict["name"] == findname:

print("姓名\t\t**\t\tqq\t\t郵箱")

print("=" * 100)

print("%s\t\t%s\t\t%s\t\t%s" % (carddict["name"],

carddict["phone"],

carddict["qq"],

carddict["email"]))

#針對找到的名片記錄執行修改和刪除操作

dealcard(carddict)

break

else:

print("抱歉,沒有找到 %s" % findname)

def dealcard(carddict):

print(carddict)

actionstr = int(input("請輸入要執行的操作修改 刪除 返回上一級"))

if actionstr == 1:

carddict["name"] = inputcartinfo(carddict["name"], "姓名: ")

print("修改名片成功")

elif actionstr == 2:

cardlist.remove(carddict)

print("刪除名片成功")

def inputcartinfo(dictvalue, tipmessage):

#提示使用者輸入的資訊

resultstr = input(tipmessage)

#針對使用者的輸入進行判斷,如果使用者輸入了內容,直接返回結果

if len(resultstr) > 0:

return resultstr

#如果使用者沒有輸入內容,返回字典中原來的值

else:

return dictvalue

#死迴圈

while true:

#呼叫選單功能

showmenu()

actionstr = int(input("請選擇執行的操作: "))

print("你選的操作是:【%d】" % actionstr)

#對使用者的資訊,通過列表的方式進行判斷

if actionstr in [1, 2, 3]:

#新增名片

if actionstr == 1:

newcard()

#顯示名片

elif actionstr == 2:

showall()

#查詢名片

elif actionstr == 3:

searchcard()

elif actionstr == 0:

print("歡迎再次使用【名片管理系統】")

break

else:

print("您輸入的不正確,請重新選擇")

名片管理系統

名片管理系統 1 需要完成的基本功能 1.新增名片 2.刪除名片 3.修改名片 4.查詢名片 5.退出系統 程式執行後,除非選擇退出系統,否則重複執行功能 cards list 所有的名片存放在這個列表裡面 顯示出所有的選擇 print print 歡迎進入名片管理系統 print 1.新增名片 p...

名片管理系統

偽 編寫 列表包字典 多個列印語句,構成了歡迎選單 流程步驟 遍歷資料容器,獲取到每乙個名片的字典 拿到了名片字典,就可以提取裡面的資料了,通過字典的鍵來取值 遍歷列表所做的事情 依次獲取列表中的成員 提示使用者 輸入乙個姓名search name input 根據這個姓名,依次到名片字典中進行比對...

名片管理系統

名片效果圖 圖截得我自己也看不下去了。usr local bin python3 import cards tools while true 顯示功能選單 cards tools.show menu action str input 請選擇希望執行的操作 print 你的選擇的操作是 s actio...