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 相关文章推荐
浅析AST抽象语法树及Python代码实现
Jun 06 Python
Python基于正则表达式实现文件内容替换的方法
Aug 30 Python
Bottle框架中的装饰器类和描述符应用详解
Oct 28 Python
python实现决策树分类(2)
Aug 30 Python
通过python实现弹窗广告拦截过程详解
Jul 10 Python
python将字典列表导出为Excel文件的方法
Sep 02 Python
解决pycharm上的jupyter notebook端口被占用问题
Dec 17 Python
Tensorflow:转置函数 transpose的使用详解
Feb 11 Python
python实现连连看游戏
Feb 14 Python
用Python在Excel里画出蒙娜丽莎的方法示例
Apr 28 Python
使用python对excel表格处理的一些小功能
Jan 25 Python
Python中Numpy和Matplotlib的基本使用指南
Nov 02 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来处理多个提交任务
2006/10/09 PHP
ThinkPHP框架实现session跨域问题的解决方法
2014/07/01 PHP
PHP编程中的__clone()方法使用详解
2015/11/27 PHP
Win10 下安装配置IIS + MySQL + nginx + php7.1.7
2017/08/04 PHP
实例讲解PHP页面静态化
2018/02/05 PHP
ThinkPHP框架实现定时执行任务的两种方法分析
2018/09/04 PHP
php设计模式之状态模式实例分析【星际争霸游戏案例】
2020/03/26 PHP
javscript对象原型的一些看法
2010/09/19 Javascript
IE下Ajax缓存问题的快速解决方法(get方式)
2014/01/09 Javascript
jQuery获取(选中)单选,复选框,下拉框中的值
2014/02/21 Javascript
jQuery实现鼠标划过展示大图的方法
2015/03/09 Javascript
基于JavaScript如何实现私有成员的语法特征及私有成员的实现方式
2015/10/28 Javascript
Angular页面间切换及传值的4种方法
2016/11/04 Javascript
js获取浏览器地址(获取第1个斜杠后的内容)
2019/09/03 Javascript
node.js中module模块的功能理解与用法实例分析
2020/02/14 Javascript
在VUE中使用lodash的debounce和throttle操作
2020/11/09 Javascript
vue+echarts+datav大屏数据展示及实现中国地图省市县下钻功能
2020/11/16 Javascript
实用的 vue tags 创建缓存导航的过程实现
2020/12/03 Vue.js
[05:05]第三天的dota2
2013/07/29 DOTA
[02:47]DOTA2亚洲邀请赛 HR战队出场宣传片
2015/02/07 DOTA
[00:32]2018DOTA2亚洲邀请赛EG出场
2018/04/03 DOTA
[49:05]Newbee vs TNC 2018国际邀请赛小组赛BO2 第一场 8.16
2018/08/17 DOTA
CSS3 简写animation
2012/05/10 HTML / CSS
澳大利亚百货商店中销量第一的商务衬衫品牌:Van Heusen
2018/07/26 全球购物
世界上最大的隐形眼镜商店:1-800 Contacts
2018/11/03 全球购物
十佳大学生村官事迹
2014/01/09 职场文书
院领导写的就业推荐信
2014/03/09 职场文书
《高尔基和他的儿子》教学反思
2014/04/09 职场文书
档案信息化建设方案
2014/05/16 职场文书
2014年四风个人对照检查及整改措施
2014/10/28 职场文书
龙猫观后感
2015/06/09 职场文书
大学班干部竞选稿
2015/11/20 职场文书
《自然之道》读后感3篇
2019/12/17 职场文书
python源码剖析之PyObject详解
2021/05/18 Python
python使用BeautifulSoup 解析HTML
2022/04/24 Python
pd.DataFrame中的几种索引变换的实现
2022/06/16 Python