Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104320
  • 博文数量: 21
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 231
  • 用 户 组: 普通用户
  • 注册时间: 2014-12-16 16:23
文章分类

全部博文(21)

文章存档

2017年(3)

2016年(9)

2015年(9)

我的朋友

分类: Python/Ruby

2015-08-29 15:56:16


  1. #!/usr/bin/python
  2. # coding=utf-8
  3. studict = {}


  4. def addfunc():
  5.     while 1:
  6.         keynum = raw_input('number: ')
  7.         if keynum.isdigit():
  8.             break
  9.         print 'number error,reinput'
  10.     name = raw_input('name: ')
  11.     sex = raw_input('sex: ')
  12.     old = raw_input('old: ')
  13.     addr = raw_input('addr: ')
  14.     QQ = raw_input('QQ: ')
  15.     studict[keynum] = (name, sex, old, addr, QQ)
  16.     print 'add success'
  17.     return studict


  18. def readfunc():
  19.     keynum = raw_input('read number: ')
  20.     if keynum not in studict:
  21.         print '%s not exist' % keynum
  22.     else:
  23.         print'姓名:%s 性别:%s 年龄:%s 所在地:%s QQ号:%s' % studict[keynum]
  24.     return studict


  25. def deletefunc():
  26.     keynum = raw_input('delte number: ')
  27.     if keynum not in studict:
  28.         print '%s not exist' % keynum
  29.     else:
  30.         print 'Are you sure?y/n'
  31.         yesorno = raw_input()
  32.         if yesorno == 'y':
  33.             studict.pop(keynum)
  34.             print 'delete %s success' % keynum
  35.     return studict


  36. def updatefunc():
  37.     keynum = raw_input('update number: ')
  38.     if keynum not in studict:
  39.         print '%s not exist' % keynum
  40.         return
  41.     name = raw_input('name: ')
  42.     sex = raw_input('sex: ')
  43.     old = raw_input('old: ')
  44.     addr = raw_input('addr: ')
  45.     QQ = raw_input('QQ: ')
  46.     studict[keynum] = (name, sex, old, addr, QQ)
  47.     print '%s update success' % keynum
  48.     return studict

  49. while 1:
  50.     print 'your operation is:add,read,delete,update'
  51.     choice = raw_input('choice operatione: ')
  52.     if choice == 'add':
  53.         addfunc()
  54.     elif choice == 'read':
  55.         readfunc()
  56.     elif choice == 'delete':
  57.         deletefunc()
  58.     elif choice == 'update':
  59.         updatefunc()


阅读(1746) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~