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中3种内建数据结构:列表、元组和字典
Nov 30 Python
Python通过poll实现异步IO的方法
Jun 04 Python
python如何把嵌套列表转变成普通列表
Mar 20 Python
python实现搜索文本文件内容脚本
Jun 22 Python
Python线程之定位与销毁的实现
Feb 17 Python
Python匿名函数/排序函数/过滤函数/映射函数/递归/二分法
Jun 05 Python
python实现超级马里奥
Mar 18 Python
python中sympy库求常微分方程的用法
Apr 28 Python
Python实现自动签到脚本功能
Aug 20 Python
爬虫代理的cookie如何生成运行
Sep 22 Python
Python APScheduler执行使用方法详解
Dec 10 Python
Python实现邮件发送的详细设置方法(遇到问题)
Jan 18 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 smarty模版引擎中的缓存应用
2009/12/11 PHP
php多文件上传功能实现原理及代码
2013/04/18 PHP
php获取远程文件的内容和大小
2015/11/03 PHP
PHP发送AT指令实例代码
2016/05/26 PHP
在PHP语言中使用JSON和将json还原成数组的方法
2016/07/19 PHP
JavaScript单元测试ABC
2012/04/12 Javascript
jQuery中prevUntil()方法用法实例
2015/01/08 Javascript
javascript模拟php函数in_array
2015/04/27 Javascript
javascript生成大小写字母
2015/07/03 Javascript
AngularJS控制器之间的通信方式详解
2016/11/03 Javascript
jQuery 的 ready()的纯js替代方法
2016/11/20 Javascript
js字符串操作总结(必看篇)
2016/11/22 Javascript
JS原生带小白点轮播图实例讲解
2017/07/22 Javascript
详解自定义ajax支持跨域组件封装
2018/02/08 Javascript
vue2.0+vuex+localStorage代办事项应用实现详解
2018/05/31 Javascript
vue watch深度监听对象实现数据联动效果
2018/08/16 Javascript
javascript中this的用法实践分析
2019/07/29 Javascript
使用layui实现的左侧菜单栏以及动态操作tab项方法
2019/09/10 Javascript
Vue 的 v-model用法实例
2020/11/23 Vue.js
[40:01]OG vs Winstrike 2018国际邀请赛小组赛BO2 第一场 8.19
2018/08/21 DOTA
python实现分页效果
2017/10/25 Python
python3安装pip3(install pip3 for python 3.x)
2018/04/03 Python
python让列表倒序输出的实例
2018/06/25 Python
pandas通过loc生成新的列方法
2018/11/28 Python
Python3.6+selenium2.53.6自动化测试_读取excel文件的方法
2019/09/06 Python
python设置代理和添加镜像源的方法
2020/02/14 Python
美国创意礼品网站:UncommonGoods
2017/02/03 全球购物
人力资源行政经理自我评价
2013/10/23 职场文书
关于礼仪的演讲稿
2014/01/04 职场文书
简历自我评价怎么写呢?
2014/01/06 职场文书
企业安全生产目标责任书
2014/07/23 职场文书
2014年妇女工作总结
2014/12/06 职场文书
团代会开幕词
2015/01/28 职场文书
MySQL触发器的使用
2021/05/24 MySQL
Pytest中skip和skipif的具体使用方法
2021/06/30 Python
golang用type-switch判断interface的实际存储类型
2022/04/14 Golang