python学习笔记(1):字典

目的:实现简单的电话薄功能,借助字典实现姓名、电话号码的简单存储、查询、删除、打印。

1新增

def person_delete(): name=raw_input("Enter the name you want to be deleted:") del pb[name] return pb

2删除

def person_delete(): name=raw_input("Enter the name you want to be deleted:") del pb[name] return pb

3打印

def print_phonebook(): print "-----phonebook----" for key in pb: print key+"-->"+pb[key] print "----End----" return

4主程序

def main(): print "This is a phonebook,please enter what you want?" print "========MANU========" print "1、ADD A PERSON" print "2、DELETE A PERSON" print "3、PRINT ALL" print "4、FIND A PERSON" print "5、QUIT" check_number=int(raw_input("Enter what you want:")) if check_number==1: person_add() elif check_number==2: person_delete() elif check_number==3: print_phonebook() elif check_number==4: find_person() elif check_number==5: exit()

5未完待续

  1. 主程序仅可执行一次,需完善可多次运行,选择结束后退出。
  2. 数据文件未保存,需在过程中保存文档。
  3. 后续实现数据文件导入(如txt、csv、xlsx)与导出。

你可能感兴趣的:(python学习笔记(1):字典)