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使用datetime模块计算各种时间间隔的方法
Mar 24 Python
python+Django+apache的配置方法详解
Jun 01 Python
Python django实现简单的邮件系统发送邮件功能
Jul 14 Python
Python使用Matplotlib实现Logos设计代码
Dec 25 Python
对命令行模式与python交互模式介绍
May 12 Python
Python完全识别验证码自动登录实例详解
Nov 24 Python
Python Sphinx使用实例及问题解决
Jan 17 Python
使用sklearn对多分类的每个类别进行指标评价操作
Jun 11 Python
python的链表基础知识点
Sep 13 Python
python 动态绘制爱心的示例
Sep 27 Python
Python图片检索之以图搜图
May 31 Python
Python探索生命起源 matplotlib细胞自动机动画演示
Apr 21 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的FTP学习(三)
2006/10/09 PHP
PHP+MySQL投票系统的设计和实现分享
2012/09/23 PHP
PHP之autoload运行机制实例分析
2014/08/28 PHP
php中in_array函数用法分析
2014/11/15 PHP
php时间函数用法分析
2016/05/28 PHP
Laravel5.1自定义500错误页面示例
2016/10/09 PHP
php 利用socket发送GET,POST请求的实例代码
2020/07/04 PHP
javascript 面向对象编程  function是方法(函数)
2009/09/17 Javascript
js trim函数 去空格函数与正则集锦
2009/11/20 Javascript
为jquery.ui.dialog 增加“在当前鼠标位置打开”的功能
2009/11/24 Javascript
用Jquery重写windows.alert方法实现思路
2013/04/03 Javascript
javascript中的startWith和endWith的几种实现方法
2013/05/07 Javascript
jquery实现弹出div,始终显示在屏幕正中间的简单实例
2014/03/08 Javascript
排序算法的javascript实现与讲解(99js手记)
2014/09/28 Javascript
跟我学习javascript的prototype使用注意事项
2015/11/17 Javascript
jQuery绑定自定义事件的魔法升级版
2016/06/30 Javascript
vue实现登录后页面跳转到之前页面
2018/01/07 Javascript
Angular搜索场景中使用rxjs的操作符处理思路
2018/05/30 Javascript
JS数组方法shift()、unshift()用法实例分析
2020/01/18 Javascript
python中matplotlib实现最小二乘法拟合的过程详解
2017/07/11 Python
python实现类之间的方法互相调用
2018/04/29 Python
python实现图片识别汽车功能
2018/11/30 Python
python仿抖音表白神器
2019/04/08 Python
使用python制作一个为hex文件增加版本号的脚本实例
2019/06/12 Python
Python unittest如何生成HTMLTestRunner模块
2020/09/08 Python
python编写实现抽奖器
2020/09/10 Python
python+excel接口自动化获取token并作为请求参数进行传参操作
2020/11/10 Python
HTML5语义化元素你真的用对了吗
2019/08/22 HTML / CSS
大学活动策划书范文
2014/01/10 职场文书
《影子》教学反思
2014/02/21 职场文书
《猴子种果树》教学反思
2014/04/26 职场文书
2014年党的群众路线学习心得体会
2014/11/05 职场文书
大学生考试作弊被抓检讨书
2014/12/27 职场文书
小学推普周活动总结
2015/05/07 职场文书
学校财务管理制度
2015/08/04 职场文书
阿里云 Windows server 2019 配置FTP
2022/04/28 Servers