python实现简单名片管理系统


Posted in Python onNovember 30, 2018

前言

之前看过一遍的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使用百度翻译进行中翻英示例
Apr 14 Python
进一步探究Python中的正则表达式
Apr 28 Python
python scp 批量同步文件的实现方法
Jan 03 Python
python 弹窗提示警告框MessageBox的实例
Jun 18 Python
Python进阶之使用selenium爬取淘宝商品信息功能示例
Sep 16 Python
Python上下文管理器类和上下文管理器装饰器contextmanager用法实例分析
Nov 07 Python
Python笔记之工厂模式
Nov 20 Python
Python对Tornado请求与响应的数据处理
Feb 12 Python
浅析Django 接收所有文件,前端展示文件(包括视频,文件,图片)ajax请求
Mar 09 Python
python 读取.nii格式图像实例
Jul 01 Python
在Python3.74+PyCharm2020.1 x64中安装使用Kivy的详细教程
Aug 07 Python
python用tkinter开发的扫雷游戏
Jun 01 Python
python3学生名片管理v2.0版
Nov 29 #Python
python实现名片管理系统
Nov 29 #Python
Python中利用aiohttp制作异步爬虫及简单应用
Nov 29 #Python
Python中logging.NullHandler 的使用教程
Nov 29 #Python
Mac下Anaconda的安装和使用教程
Nov 29 #Python
windows7 32、64位下python爬虫框架scrapy环境的搭建方法
Nov 29 #Python
解决pycharm py文件运行后停止按钮变成了灰色的问题
Nov 29 #Python
You might like
PHP代码网站如何防范SQL注入漏洞攻击建议分享
2012/03/01 PHP
PHP中设置时区方法小结
2012/06/03 PHP
php中字符集转换iconv函数使用总结
2014/10/11 PHP
利用PHP生成静态html页面的原理
2016/09/30 PHP
PHP实现生成模糊图片的方法示例
2017/12/21 PHP
PHP如何实现阿里云短信sdk灵活应用在项目中的方法
2019/06/14 PHP
PHP常量及变量区别原理详解
2020/08/14 PHP
JavaScript 基于原型的对象(创建、调用)
2009/10/16 Javascript
基于KMP算法JavaScript的实现方法分析
2013/05/03 Javascript
Jquery实现Div上下移动示例
2014/04/23 Javascript
深入理解JavaScript中的对象复制(Object Clone)
2016/05/18 Javascript
Easyui Tree获取当前选择节点的所有顶级父节点
2017/02/14 Javascript
详解使用JS如何制作简单的ASCII图与单极图
2017/03/31 Javascript
详解在Angularjs中ui-sref和$state.go如何传递参数
2017/04/24 Javascript
在小程序中使用canvas的方法示例
2018/09/17 Javascript
JS实现带阴历的日历功能详解
2019/01/24 Javascript
详解为什么Vue中的v-if和v-for不建议一起用
2021/01/13 Vue.js
[02:35]DOTA2超级联赛专访XB 难忘一年九冠称王
2013/06/20 DOTA
Python入门篇之编程习惯与特点
2014/10/17 Python
Python中一些自然语言工具的使用的入门教程
2015/04/13 Python
Windows下PyMongo下载及安装教程
2015/04/27 Python
用tensorflow构建线性回归模型的示例代码
2018/03/05 Python
对Python实现累加函数的方法详解
2019/01/23 Python
Python实现点云投影到平面显示
2020/01/18 Python
Python数据可视化实现漏斗图过程图解
2020/07/20 Python
python statsmodel的使用
2020/12/21 Python
详解HTML5如何使用可选样式表为网站或应用添加黑暗模式
2020/04/07 HTML / CSS
韩国现代百货官网:Hmall
2018/03/21 全球购物
爱奇艺VIP会员:大剧抢先看
2018/07/11 全球购物
以实惠的价格轻松租车,免费取消:Easyrentcars
2019/07/16 全球购物
企业门卫岗位职责
2013/12/12 职场文书
园林设计专业毕业生求职信
2014/03/23 职场文书
《新型玻璃》教学反思
2014/04/13 职场文书
go mod 安装依赖 unkown revision问题的解决方案
2021/05/06 Golang
canvas绘制折线路径动画实现
2021/05/12 Javascript
nginx结合openssl实现https的方法
2021/07/25 Servers