這篇文章給大家分享的是有關(guān)python怎么實現(xiàn)名片管理系統(tǒng)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
10年積累的成都網(wǎng)站制作、網(wǎng)站設(shè)計經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有曲江免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。python實現(xiàn)名片管理系統(tǒng)
能實現(xiàn)如下功能:
*****************
名片管理系統(tǒng)1.添加名片
2.刪除名片
3.修改名片
4.查詢名片
5.退出系統(tǒng)
0.顯示所有名片
*****************
添加名片
編程思路 先創(chuàng)建一個臨時的 templist 變量,通過 templist.append()方法,增加,姓名,手機號,地址等信息,然后把templist列表追加到 mainList列表中。
def increMem(aList): tempList = [] tempName = input("輸入新建名片名字:") tempList.append(tempName) while True: tempPhone = input("輸入新建聯(lián)系人手機號:") if tempPhone.isnumeric(): break else: print("輸入有誤,重新輸入") tempList.append(tempPhone) tempAddr = input("輸入新建聯(lián)系人地址:") tempList.append(tempAddr) print("輸入新建聯(lián)系人信息:") showList(tempList) aList.append(tempList)
注意:
手機號都是數(shù)字,可以通過 list.isnumeric()方法判斷是否是純數(shù)字字符串,不是返回False
刪除名片
編程思想:首先盤算是否是空,如果是空返回,然后先定位刪除聯(lián)系人的索引值,最后通過del()函數(shù)刪除聯(lián)系人。
def delMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請先添加聯(lián)系人!") return tempName = input("輸入要刪除的聯(lián)系人:") for mumList in aList: if tempName != mumList[0] : i += 1 continue else: showList(aList[i]) while True: tempIn = input("是否刪除此聯(lián)系人: Y(是)\t N(否) :") if tempIn =="Y" or tempIn == "y": del(aList[i]) print("刪除成功!") return elif tempIn == "N" or tempIn == "n": print("重新輸入聯(lián)系人!") delMem(aList) return else: print("輸入有誤,重新輸入!") if i == len(aList): print("輸入的聯(lián)系熱不存在,請重新輸入!") delMem(aList)
注意:
如果刪除的聯(lián)系人不存在,怎么處理?對mainList遍歷,每一個元素都是一個 list 結(jié)構(gòu)的元素。如果 要刪除的聯(lián)系人不等于numLinst[0],則繼續(xù),i 自增1.如果遍歷所有的,都沒有,則i = len(aList),則判斷聯(lián)系人不存在,重新輸入。
修改名片
修改名片,先定位后修改。
def modMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請先添加聯(lián)系人!") return tempList = input("輸入需要修改的聯(lián)系人:") for numList in aList: if tempList != numList[0] : i += 1 continue else: tempInf = input("輸入修改的信息:") if tempInf.isnumeric(): numList[1] = tempInf else: numList[2] = tempInf if i == len(aList): print("輸入有誤,重新輸入!") modMem(aList)
注意:
is.numeric()方法,判斷,全是數(shù)字,則是修改的是電話號碼,否則則是地址。
查找名片
先定位,再輸出。注意分析沒有聯(lián)系人時候情況
def LocaMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請先添加聯(lián)系人!") return tempList = input("輸入需要查找的聯(lián)系人:") for numList in aList: if tempList != numList[0] : i += 1 continue else: showList(numList) if i == len(aList): print("輸入有誤,重新輸入!") modMem(aList)
完整的程序塊
def men(): print("\t*****************") print("\t 名片管理系統(tǒng)\n") print("\t 1.添加名片\n") print("\t 2.刪除名片\n") print("\t 3.修改名片\n") print("\t 4.查詢名片\n") print("\t 5.退出系統(tǒng)\n") print("\t 0.顯示所有名片\n") print("\t*****************") def increMem(aList): tempList = [] tempName = input("輸入新建名片名字:") tempList.append(tempName) while True: tempPhone = input("輸入新建聯(lián)系人手機號:") if tempPhone.isnumeric(): break else: print("輸入有誤,重新輸入") tempList.append(tempPhone) tempAddr = input("輸入新建聯(lián)系人地址:") tempList.append(tempAddr) print("輸入新建聯(lián)系人信息:") showList(tempList) aList.append(tempList) def showList(aList): print("名字: %s"%aList[0],\ "電話:%s"%aList[1], \ "地址:%s"%aList[2],"\n") def showMem(aList): if len(aList) == 0: print("沒有聯(lián)系人!") for mumList in aList: print("名字: %s"%mumList[0],\ "電話:%s"%mumList[1], \ "地址:%s"%mumList[2],"\n") def delMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請先添加聯(lián)系人!") return tempName = input("輸入要刪除的聯(lián)系人:") for mumList in aList: if tempName != mumList[0] : i += 1 continue else: showList(aList[i]) while True: tempIn = input("是否刪除此聯(lián)系人: Y(是)\t N(否) :") if tempIn =="Y" or tempIn == "y": del(aList[i]) print("刪除成功!") return elif tempIn == "N" or tempIn == "n": print("重新輸入聯(lián)系人!") delMem(aList) return else: print("輸入有誤,重新輸入!") if i == len(aList): print("輸入的聯(lián)系熱不存在,請重新輸入!") delMem(aList) def modMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請先添加聯(lián)系人!") return tempList = input("輸入需要修改的聯(lián)系人:") for numList in aList: if tempList != numList[0] : i += 1 continue else: tempInf = input("輸入修改的信息:") if tempInf.isnumeric(): numList[1] = tempInf else: numList[2] = tempInf if i == len(aList): print("輸入有誤,重新輸入!") modMem(aList) def LocaMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請先添加聯(lián)系人!") return tempList = input("輸入需要查找的聯(lián)系人:") for numList in aList: if tempList != numList[0] : i += 1 continue else: showList(numList) if i == len(aList): print("輸入有誤,重新輸入!") modMem(aList) if __name__ == "__main__": mainList = [] men() while True: index = input("輸入任務(wù)編號:") if not index.isnumeric(): print("請輸入索引編號(1-4):") continue index = int(index) #遍歷名片 if index == 0: showMem(mainList) #增加名片 if index == 1: increMem(mainList) if index == 2: delMem(mainList) if index == 3: modMem(mainList) if index == 4: LocaMem(mainList) if index == 5: print("退出系統(tǒng)!") break
感謝各位的閱讀!關(guān)于“python怎么實現(xiàn)名片管理系統(tǒng)”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)頁標題:python怎么實現(xiàn)名片管理系統(tǒng)-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://bm7419.com/article6/dgdgog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、靜態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、網(wǎng)站維護、電子商務(wù)、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)