python实现简单名片管理系统
作者:谦190 时间:2023-06-13 08:03:12
前言
之前看过一遍的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
来源:https://blog.csdn.net/u013355826/article/details/78773410
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python+SeaTable实现生成条形码图片并写入表格
![](https://img.aspxhome.com/file/2023/5/124395_0s.png)
python读取文本中数据并转化为DataFrame的实例
![](https://img.aspxhome.com/file/2023/5/77785_0s.jpg)
使用pandas忽略行列索引,纵向拼接多个dataframe
四大因素扼杀了中国人的创造力
python opencv 画外接矩形框的完整代码
![](https://img.aspxhome.com/file/2023/3/80413_0s.png)
用js来解决ajax读取页面乱码
python递归删除指定目录及其所有内容的方法
python编程控制Android手机操作技巧示例
![](https://img.aspxhome.com/file/2023/3/69553_0s.png)
Python自动登录126邮箱的方法
为你总结一些php系统类函数
python操作redis的方法
使用SQL SERVER存储过程实现历史数据迁移方式
![](https://img.aspxhome.com/file/2023/9/89689_0s.jpg)
Python视频爬虫实现下载头条视频功能示例
![](https://img.aspxhome.com/file/2023/8/121478_0s.jpg)
Python 内置函数进制转换的用法(十进制转二进制、八进制、十六进制)
javaweb中mysql数据库连接步骤方法及其实例
oracle 时间格式的调整
微信小程序-详解数据缓存
![](https://img.aspxhome.com/file/2023/0/136130_0s.png)
python机器学习之神经网络(一)
![](https://img.aspxhome.com/file/2023/9/130809_0s.jpg)
MySql数据库基本命令集会
pip安装路径修改的详细方法步骤
![](https://img.aspxhome.com/file/2023/7/130567_0s.png)