python實(shí)現(xiàn)名片管理器的示例代碼
更新時(shí)間:2019年12月17日 11:01:08 作者:易擇365
這篇文章主要介紹了python實(shí)現(xiàn)名片管理器的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
編寫程序,完成“名片管理器”項(xiàng)目
需要完成的基本功能:
- 添加名片
- 刪除名片
- 修改名片
- 查詢名片
- 退出系統(tǒng)
程序運(yùn)行后,除非選擇退出系統(tǒng),否則重復(fù)執(zhí)行功能
mingp.py
# 名片類:(參數(shù)) # # 添加名片功能 # # 刪除名片功能: # # 修改名片功能: # # 查詢名片功能: class MingPian(): def __init__(self,all_dict,name,age): self.all_dict=all_dict self.name=name self.age=age def tianjia(self): my_dict = {"name": self.name, "age": self.age} self.all_dict[self.name]=my_dict print("添加名片成功....") return self.all_dict # print(self.all_dict) #測試添加函數(shù)可否正常執(zhí)行 def shanchu(self): if self.name in self.all_dict: del self.all_dict[self.name] print("刪除成功") else: print("輸入名字有誤") return self.all_dict def xiugai(self): if self.name in self.all_dict: self.age = input("請輸入修改后的年齡:") self.all_dict[self.name]["age"] = self.age print("修改成功") else: print("輸入名字有誤") return self.all_dict def chaxun(self): if self.name in self.all_dict: n = self.all_dict[self.name]["name"] a = self.all_dict[self.name]["age"] print("姓名:%s 年齡:%s" % (n, a)) else: print("輸入名字有誤") #test # all_dict = {} # MingPian(all_dict,'xiaoming','20').tianjia()
base.py
# 選擇判斷函數(shù): from mingpian.mingp import MingPian class Base(MingPian): def __init__(self,all_dict,name,age,index): #為了能使用或擴(kuò)展父類的行為,最好顯示調(diào)用父類的__init__方法 # 子類調(diào)用父類的構(gòu)造函數(shù)進(jìn)行初始化 # 通過子類把參數(shù)傳給父類(self不能少,self只有在實(shí)例化和實(shí)例調(diào)用類時(shí)才能省略,此處不是) #super(Base,self).__init__(all_dict,name,age) MingPian.__init__(self,all_dict,name,age) self.index=index #初始化 def caozuo(self): if self.index == "1": self.name = input("請輸入您的名字:") self.age = input("請輸入您的年齡:") # 子類調(diào)用父類方法 # 子類在調(diào)用父類方法必須要傳self MingPian.tianjia(self) elif self.index == "2": self.name = input("請輸入要?jiǎng)h除數(shù)據(jù)的名字:") MingPian.shanchu(self) elif self.index == "3": self.name = input("請輸入要修改信息人的名字:") MingPian.xiugai(self) elif self.index == "4": self.name = input("請輸入您要查詢的名字:") MingPian.chaxun(self) elif self.index == "5": print("歡迎下次使用,再見!") exit()
main.py
# where True: # 展示菜單函數(shù) # 選擇判斷函數(shù)() # 判斷選擇的操作菜單 from mingpian.base import Base all_dict = {} info_str = """1.添加名片 2.刪除名片 3.修改名片 4.查詢名片 5.退出系統(tǒng) 請選擇:""" while True: index = input(info_str) kaishi=Base(all_dict,0,0,index) kaishi.caozuo()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 深入解析Python中的上下文管理器
- Python深入學(xué)習(xí)之上下文管理器
- Python中的with語句與上下文管理器學(xué)習(xí)總結(jié)
- Python中的上下文管理器和with語句的使用
- Python with語句上下文管理器兩種實(shí)現(xiàn)方法分析
- Python上下文管理器和with塊詳解
- python 上下文管理器使用方法小結(jié)
- 深入學(xué)習(xí)Python中的上下文管理器與else塊
- Python中的上下文管理器相關(guān)知識詳解
- Python上下文管理器全實(shí)例詳解
- Python上下文管理器類和上下文管理器裝飾器contextmanager用法實(shí)例分析
相關(guān)文章
Python常用模塊之threading和Thread模塊及線程通信
這篇文章主要介紹了Python常用模塊之threading和Thread模塊及線程通信,文章為圍繞主題的相關(guān)內(nèi)容展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友看可以參考一下方法2022-06-06Zabbix實(shí)現(xiàn)微信報(bào)警功能
這篇文章主要介紹了Zabbix實(shí)現(xiàn)微信報(bào)警的相關(guān)資料,本文圖文并茂介紹的非常詳細(xì),需要的朋友可以參考下2016-10-10Python輕量級ORM框架Peewee訪問sqlite數(shù)據(jù)庫的方法詳解
這篇文章主要介紹了Python輕量級ORM框架Peewee訪問sqlite數(shù)據(jù)庫的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了ORM框架的概念、功能及peewee的安裝、使用及操作sqlite數(shù)據(jù)庫的方法,需要的朋友可以參考下2017-07-07TensorFlow和keras中GPU使用的設(shè)置操作
這篇文章主要介紹了TensorFlow和keras中GPU使用的設(shè)置操作,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05VTK與Python實(shí)現(xiàn)機(jī)械臂三維模型可視化詳解
這篇文章主要介紹了VTK與Python實(shí)現(xiàn)機(jī)械臂三維模型可視化詳解,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12