本文主要是介绍python实现名片管理系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
——————————————————————————————————————————————————————
想要掌握什么知识,就需要在什么花费时间,浮躁的看,过目即忘,再加上学完了,并不使用,过几天都忘关了。
学以致用!学习Python时候,也要想想,如果是C/C++如何编程实现。一遍一遍的写,一遍一遍的学习。
明天会感谢自己今天的努力!
——————————————————————————————————————————————————————
前言
之前看过一遍的python教程,真的是自己看过一遍,python的程序能看懂,但是很难去实现。比较困难的自己实现一些代码,找工作原因,自己又认认真真的看书,敲代码,后来看到了这个题目,想把之前学习的python常用的数据类型复习下。花了一点儿时间,编程实现了。
python实现明信片管理系统
名片管理系统
1.添加名片
2.删除名片
3.修改名片
4.查询名片
5.退出系统
0.显示所有名片
*****************
添加名片
def increMem(aList):tempList = [] tempName = input("输入新建名片名字:")tempList.append(tempName)while True:tempPhone = input("输入新建联系人手机号:") if tempPhone.isnumeric(): breakelse: print("输入有误,重新输入") tempList.append(tempPhone)tempAddr = input("输入新建联系人地址:")tempList.append(tempAddr)print("输入新建联系人信息:")showList(tempList)aList.append(tempList)
注意:
删除名片
def delMem(aList):i = 0if len(aList) == 0 : print("没有联系人,请先添加联系人!")returntempName = input("输入要删除的联系人:")for mumList in aList:if tempName != mumList[0] :i += 1continueelse: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)returnelse:print("输入有误,重新输入!") if i == len(aList):print("输入的联系热不存在,请重新输入!")delMem(aList)
注意:
修改名片
修改名片,先定位后修改。def modMem(aList):i = 0if len(aList) == 0 : print("没有联系人,请先添加联系人!")returntempList = input("输入需要修改的联系人:")for numList in aList:if tempList != numList[0] :i += 1continueelse:tempInf = input("输入修改的信息:")if tempInf.isnumeric():numList[1] = tempInfelse:numList[2] = tempInfif i == len(aList):print("输入有误,重新输入!")modMem(aList)
注意:
查找名片
先定位,再输出。注意分析没有联系人时候情况def LocaMem(aList):i = 0if len(aList) == 0 : print("没有联系人,请先添加联系人!")returntempList = input("输入需要查找的联系人:")for numList in aList:if tempList != numList[0] :i += 1continueelse: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(): breakelse: 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 = 0if len(aList) == 0 : print("没有联系人,请先添加联系人!")returntempName = input("输入要删除的联系人:")for mumList in aList:if tempName != mumList[0] :i += 1continueelse: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)returnelse:print("输入有误,重新输入!") if i == len(aList):print("输入的联系热不存在,请重新输入!")delMem(aList)
def modMem(aList):i = 0if len(aList) == 0 : print("没有联系人,请先添加联系人!")returntempList = input("输入需要修改的联系人:")for numList in aList:if tempList != numList[0] :i += 1continueelse:tempInf = input("输入修改的信息:")if tempInf.isnumeric():numList[1] = tempInfelse:numList[2] = tempInfif i == len(aList):print("输入有误,重新输入!")modMem(aList)
def LocaMem(aList):i = 0if len(aList) == 0 : print("没有联系人,请先添加联系人!")returntempList = input("输入需要查找的联系人:")for numList in aList:if tempList != numList[0] :i += 1continueelse: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):")continueindex = 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实现名片管理系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!