import os import pickle # 查看地址 print(id(0),id('0'),id(int('0')),id(str(0))) a = str(0) print(a) b = '0' print(b) print(a==b)#true print(id(a),id(b)) print(id(a)==id(b))#false # 名片關係系統 # 添加名片 # 刪除名片 # 修改名片 # 查詢名片 # 顯示所有 # 退出 # 字段:名字、qq號、微信、地址 class info(): def __init__(self,name,qq,wechat,add): self.name = name self.qq = qq self.wechat = wechat self.add = add infoLst = [] if os.path.exists('info.txt'): with open('info.txt', 'rb') as file: infoLst = pickle.load(file) while True: print('名片關係系統') print('1.添加名片') print('2.刪除名片') print('3.修改名片') print('4.查詢名片') print('5.顯示所有') print('6.退出系統') select = input('請輸入') choiseLst = ['1','2','3','4','5','6'] if select not in choiseLst: print('輸入錯誤,請重新輸入') continue if select == '6': with open('info.txt','wb') as file: pickle.dump(infoLst,file) '謝謝使用' exit() if select == '1': name = input('請輸入姓名') qq = input('請輸入qq號') wechat = input('請輸入微信號') add = input('請輸入地址') infoLst.append(info(name,qq,wechat,add)) elif select == '2': name = input('請輸入刪除姓名') flag = True for temp in infoLst: if(temp.name == name): infoLst.remove(temp) print('刪除成功') flag = False break if flag: print('查無此人') elif select == '3': name = input('請輸入修改姓名') flag = True for temp in infoLst: if(temp.name == name): temp.name = input('原姓名:%s,請修改'%temp.name) temp.qq = input('原qq:%s,請修改'%temp.qq) temp.wechat = input('原微信:%s,請修改'%temp.wechat) temp.add = input('原地址:%s,請修改'%temp.wechat) flag = False print('修改成功') break if flag:print('查無此人') elif select == '4': name = input('請輸入查詢姓名') flag = True for temp in infoLst: if(temp.name == name): print('姓名\tqq\t微信\t地址') print('%s\t%s\t%s\t%s'%(temp.name,temp.qq,temp.wechat,temp.add)) flag = False break if flag: print('查無此人') elif select == '5': print('姓名\tqq\t微信\t地址') for temp in infoLst: print('%s\t%s\t%s\t%s' % (temp.name, temp.qq, temp.wechat, temp.add))
Python入門記錄7
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.