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的Django框架编写从Google Adsense中获得报表的应用
Apr 17 Python
在Python中操作文件之seek()方法的使用教程
May 24 Python
Python基于tkinter模块实现的改名小工具示例
Jul 27 Python
Django数据库操作的实例(增删改查)
Sep 04 Python
Python使用getpass库读取密码的示例
Oct 10 Python
详解PyTorch批训练及优化器比较
Apr 28 Python
pandas带有重复索引操作方法
Jun 08 Python
PyCharm代码回滚,恢复历史版本的解决方法
Oct 22 Python
Python2和Python3.6环境解决共存问题
Nov 09 Python
Windows10下 python3.7 安装 facenet的教程
Sep 10 Python
pandas factorize实现将字符串特征转化为数字特征
Dec 19 Python
Python的赋值、深拷贝与浅拷贝的区别详解
Feb 12 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学习笔记之二 php入门知识
2011/01/12 PHP
PHP学习 变量使用总结
2011/03/24 PHP
php curl的深入解析
2013/06/02 PHP
PHP实现绘制3D扇形统计图及图片缩放实例
2014/10/01 PHP
php将textarea数据提交到mysql出现很多空格的解决方法
2014/12/19 PHP
PHP设计模式(九)外观模式Facade实例详解【结构型】
2020/05/02 PHP
Firefox div高度自适应
2009/04/28 Javascript
JS的encodeURI和java的URLDecoder.decode使用介绍
2014/05/08 Javascript
JavaScript实现生成GUID(全局统一标识符)
2014/09/05 Javascript
javascript实现点击提交按钮后显示loading的方法
2015/07/03 Javascript
javascript多物体运动实现方法分析
2016/01/08 Javascript
jQuery获取checkbox选中的值
2016/01/28 Javascript
浅析JavaScript 箭头函数 generator Date JSON
2016/05/23 Javascript
原生JavaScript编写canvas版的连连看游戏
2016/05/29 Javascript
JQ选择器_选择同类元素的第N个子元素的实现方法
2016/09/08 Javascript
详解jQuery中的事件
2016/12/14 Javascript
js实现图片左右滚动效果
2017/02/27 Javascript
JS实现点击循环切换显示内容的方法
2017/10/19 Javascript
vue.js 获取select中的value实例
2018/03/01 Javascript
Vue初始化中的选项合并之initInternalComponent详解
2020/06/11 Javascript
Python实现国外赌场热门游戏Craps(双骰子)
2015/03/31 Python
python下读取公私钥做加解密实例详解
2017/03/29 Python
Python数据可视化正态分布简单分析及实现代码
2017/12/04 Python
Python实现控制台中的进度条功能代码
2017/12/22 Python
Pycharm以root权限运行脚本的方法
2019/01/19 Python
python2.7使用plotly绘制本地散点图和折线图
2019/04/02 Python
python爬虫 urllib模块url编码处理详解
2019/08/20 Python
call在Python中改进数列的实例讲解
2020/12/09 Python
创建索引时需要注意的事项
2013/05/13 面试题
最新茶叶店创业计划书
2014/01/14 职场文书
葛优非诚勿扰搞笑征婚台词
2014/03/17 职场文书
电大毕业个人生自我鉴定
2014/03/26 职场文书
召开会议通知范文
2015/04/15 职场文书
2015年派出所工作总结
2015/04/24 职场文书
初中生活随笔
2015/08/15 职场文书
Python 一键获取电脑浏览器的账号密码
2022/05/11 Python