python实现简单名片管理系统

Viveka ·
更新时间:2024-09-21
· 982 次阅读

前言

之前看过一遍的python教程,真的是自己看过一遍,python的程序能看懂,但是很难去实现。比较困难的自己实现一些代码,找工作原因,自己又认认真真的看书,敲代码,后来看到了这个题目,想把之前学习的python常用的数据类型复习下。花了一点儿时间,编程实现了。

python实现名片管理系统

能实现如下功能:

*****************
名片管理系统

1.添加名片

2.删除名片

3.修改名片

4.查询名片

5.退出系统

0.显示所有名片

*****************

添加名片

编程思路 先创建一个临时的 templist 变量,通过 templist.append()方法,增加,姓名,手机号,地址等信息,然后把templist列表追加到 mainList列表中。

def increMem(aList): tempList = [] tempName = input("输入新建名片名字:") tempList.append(tempName) while True: tempPhone = input("输入新建联系人手机号:") if tempPhone.isnumeric(): break else: print("输入有误,重新输入") tempList.append(tempPhone) tempAddr = input("输入新建联系人地址:") tempList.append(tempAddr) print("输入新建联系人信息:") showList(tempList) aList.append(tempList)

注意:

手机号都是数字,可以通过 list.isnumeric()方法判断是否是纯数字字符串,不是返回False

删除名片

编程思想:首先盘算是否是空,如果是空返回,然后先定位删除联系人的索引值,最后通过del()函数删除联系人。

def delMem(aList): i = 0 if len(aList) == 0 : print("没有联系人,请先添加联系人!") return tempName = input("输入要删除的联系人:") for mumList in aList: if tempName != mumList[0] : i += 1 continue else: showList(aList[i]) while True: tempIn = input("是否删除此联系人: Y(是)\t N(否) :") if tempIn =="Y" or tempIn == "y": del(aList[i]) print("删除成功!") return elif tempIn == "N" or tempIn == "n": print("重新输入联系人!") delMem(aList) return else: print("输入有误,重新输入!") if i == len(aList): print("输入的联系热不存在,请重新输入!") delMem(aList)

注意:

如果删除的联系人不存在,怎么处理?对mainList遍历,每一个元素都是一个 list 结构的元素。如果 要删除的联系人不等于numLinst[0],则继续,i 自增1.如果遍历所有的,都没有,则i = len(aList),则判断联系人不存在,重新输入。

修改名片

修改名片,先定位后修改。

def modMem(aList): i = 0 if len(aList) == 0 : print("没有联系人,请先添加联系人!") return tempList = input("输入需要修改的联系人:") 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()方法,判断,全是数字,则是修改的是电话号码,否则则是地址。

查找名片

先定位,再输出。注意分析没有联系人时候情况

def LocaMem(aList): i = 0 if len(aList) == 0 : print("没有联系人,请先添加联系人!") return tempList = input("输入需要查找的联系人:") 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 名片管理系统\n") print("\t 1.添加名片\n") print("\t 2.删除名片\n") print("\t 3.修改名片\n") print("\t 4.查询名片\n") print("\t 5.退出系统\n") print("\t 0.显示所有名片\n") print("\t*****************") def increMem(aList): tempList = [] tempName = input("输入新建名片名字:") tempList.append(tempName) while True: tempPhone = input("输入新建联系人手机号:") if tempPhone.isnumeric(): break else: print("输入有误,重新输入") tempList.append(tempPhone) tempAddr = input("输入新建联系人地址:") tempList.append(tempAddr) print("输入新建联系人信息:") 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("没有联系人!") 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("没有联系人,请先添加联系人!") return tempName = input("输入要删除的联系人:") for mumList in aList: if tempName != mumList[0] : i += 1 continue else: showList(aList[i]) while True: tempIn = input("是否删除此联系人: Y(是)\t N(否) :") if tempIn =="Y" or tempIn == "y": del(aList[i]) print("删除成功!") return elif tempIn == "N" or tempIn == "n": print("重新输入联系人!") delMem(aList) return else: print("输入有误,重新输入!") if i == len(aList): print("输入的联系热不存在,请重新输入!") delMem(aList) def modMem(aList): i = 0 if len(aList) == 0 : print("没有联系人,请先添加联系人!") return tempList = input("输入需要修改的联系人:") 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("没有联系人,请先添加联系人!") return tempList = input("输入需要查找的联系人:") 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("输入任务编号:") 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("退出系统!") break 您可能感兴趣的文章:详解Python做一个名片管理系统python实现名片管理系统python面向对象实现名片管理系统文件版Python版名片管理系统python实现一个函数版的名片管理系统过程解析Python实现的登录验证系统完整案例【基于搭建的MVC框架】Python实现的银行系统模拟程序完整案例python爬虫爬取微博评论案例详解Python实现的爬取豆瓣电影信息功能案例Python综合应用名片管理系统案例详解



名片 系统 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号