python實(shí)現(xiàn)簡(jiǎn)單名片管理系統(tǒng)
前言
之前看過一遍的python教程,真的是自己看過一遍,python的程序能看懂,但是很難去實(shí)現(xiàn)。比較困難的自己實(shí)現(xiàn)一些代碼,找工作原因,自己又認(rèn)認(rèn)真真的看書,敲代碼,后來看到了這個(gè)題目,想把之前學(xué)習(xí)的python常用的數(shù)據(jù)類型復(fù)習(xí)下?;艘稽c(diǎn)兒時(shí)間,編程實(shí)現(xiàn)了。
python實(shí)現(xiàn)名片管理系統(tǒng)
能實(shí)現(xiàn)如下功能:
*****************
名片管理系統(tǒng)1.添加名片
2.刪除名片
3.修改名片
4.查詢名片
5.退出系統(tǒng)
0.顯示所有名片
*****************
添加名片
編程思路 先創(chuàng)建一個(gè)臨時(shí)的 templist 變量,通過 templist.append()方法,增加,姓名,手機(jī)號(hào),地址等信息,然后把templist列表追加到 mainList列表中。
def increMem(aList): tempList = [] tempName = input("輸入新建名片名字:") tempList.append(tempName) while True: tempPhone = input("輸入新建聯(lián)系人手機(jī)號(hào):") if tempPhone.isnumeric(): break else: print("輸入有誤,重新輸入") tempList.append(tempPhone) tempAddr = input("輸入新建聯(lián)系人地址:") tempList.append(tempAddr) print("輸入新建聯(lián)系人信息:") showList(tempList) aList.append(tempList)
注意:
手機(jī)號(hào)都是數(shù)字,可以通過 list.isnumeric()方法判斷是否是純數(shù)字字符串,不是返回False
刪除名片
編程思想:首先盤算是否是空,如果是空返回,然后先定位刪除聯(lián)系人的索引值,最后通過del()函數(shù)刪除聯(lián)系人。
def delMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請(qǐng)先添加聯(lián)系人!") return tempName = input("輸入要?jiǎng)h除的聯(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)系熱不存在,請(qǐng)重新輸入!") delMem(aList)
注意:
如果刪除的聯(lián)系人不存在,怎么處理?對(duì)mainList遍歷,每一個(gè)元素都是一個(gè) list 結(jié)構(gòu)的元素。如果 要?jiǎng)h除的聯(lián)系人不等于numLinst[0],則繼續(xù),i 自增1.如果遍歷所有的,都沒有,則i = len(aList),則判斷聯(lián)系人不存在,重新輸入。
修改名片
修改名片,先定位后修改。
def modMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請(qǐng)先添加聯(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ù)字,則是修改的是電話號(hào)碼,否則則是地址。
查找名片
先定位,再輸出。注意分析沒有聯(lián)系人時(shí)候情況
def LocaMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請(qǐng)先添加聯(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)系人手機(jī)號(hào):") 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)系人,請(qǐng)先添加聯(lián)系人!") return tempName = input("輸入要?jiǎng)h除的聯(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)系熱不存在,請(qǐng)重新輸入!") delMem(aList) def modMem(aList): i = 0 if len(aList) == 0 : print("沒有聯(lián)系人,請(qǐng)先添加聯(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)系人,請(qǐng)先添加聯(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ù)編號(hào):") if not index.isnumeric(): print("請(qǐng)輸入索引編號(hào)(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
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 詳解Python做一個(gè)名片管理系統(tǒng)
- python實(shí)現(xiàn)名片管理系統(tǒng)
- 名片管理系統(tǒng)python版
- 一個(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 dict字典基本操作(添加、修改、刪除鍵值對(duì))
本文主要介紹了Python dict字典基本操作,主要包括字典添加、修改、刪除鍵值對(duì)等,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09Python讀取Pickle文件信息并計(jì)算與當(dāng)前時(shí)間間隔的方法分析
這篇文章主要介紹了Python讀取Pickle文件信息并計(jì)算與當(dāng)前時(shí)間間隔的方法,涉及Python基于pickle模塊操作文件屬性相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-01-01正確的理解和使用Django信號(hào)(Signals)
這篇文章主要介紹了如何正確的理解和使用Django信號(hào)(Signals),幫助大家更好的理解和學(xué)習(xí)是Django,感興趣的朋友可以了解下2021-04-04python groupby 函數(shù) as_index詳解
今天小編就為大家分享一篇python groupby 函數(shù) as_index詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12nginx黑名單和django限速,最簡(jiǎn)單的防惡意請(qǐng)求方法分享
今天小編就為大家分享一篇nginx黑名單和django限速,最簡(jiǎn)單的防惡意請(qǐng)求方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-08-08python+appium+yaml移動(dòng)端自動(dòng)化測(cè)試框架實(shí)現(xiàn)詳解
這篇文章主要介紹了python+appium+yaml移動(dòng)端自動(dòng)化測(cè)試框架實(shí)現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Python中threading模塊join函數(shù)用法實(shí)例分析
這篇文章主要介紹了Python中threading模塊join函數(shù)用法,以實(shí)例形式較為詳細(xì)的分析了join函數(shù)的功能與使用方法,需要的朋友可以參考下2015-06-06Python中NumPy的線性代數(shù)子模塊linalg詳解
這篇文章主要介紹了Python中NumPy的線性代數(shù)子模塊linalg詳解,NumPy 的線性代數(shù)子模塊linalg提供了 20 余個(gè)函數(shù),用于求解行列式、逆矩陣、特征值、特征向量,以及矩陣分解等,需要的朋友可以參考下2023-08-08