In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "python how to achieve the address book system", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "python how to achieve the address book system" bar!
First of all, let's show you the effect of the main menu of this system.
As follows:
Second, step analysis
1. First create a main.py file:
Main.py:
# Import the management system module from managerSystem import ContactManager# to start the management system if _ _ name__=='__main__': contact_manager=ContactManager () contact_manager.run ()
2. The second step is to display the main menu list:
* create a managerSystem.py:
* write a static method in mangagerSystem.py:
# 2.1 implementation of system menu function-static method @ staticmethod def show_menu (): print ('Please select the following functions:') print ('1, add contact') print ('2, delete contact') print ('3, modify contact information') print ('4, query contact information') print ('5, Show all contact information') print ('6, save contact information') print ('7, exit the system')
3. The third step is to realize the function:
For example, add the contact function:
Def add_contact (self): # 1. The user enters the name, gender, phone number, name = input ('Please enter your name:') gender = input ('Please enter your gender:') tel = input ('Please enter your phone number:') # 2. Create the contact object contact = Contact (name, gender, tel) # 3. Add this object to the contact list self.contact_list.append (contact) print (self.contact_list) print (contact)
4. Create contact table:
Contact:
Class Contact (object): def _ _ init__ (self,name,gender,tel): # formal parameter name,gender,tel # instance properties self.name=name self.gender=gender self.tel=tel def _ _ str__ (self): return f'{self.name}, {self.gender}, {self.tel}'
5. Record data: contact.data:
Finally, I'll give you the managerSystem.py source code:
From contact import Contactclass ContactManager (object): def _ int__ (self): self.contact_list= [] def run (self): self.load_contact () while True: self.show_menu () menu_num=int (input ('enter the function serial number you need:') if menu_num==1: self. Add_contact () elif menu_num==2: self.del_contact () elif menu_num==3: self.modify_contact () elif menu_num==4: self.search_contact () elif menu_num==5: self.show_contact () elif menu_num==6: Self.save_contact () elif menu_num==7: break @ staticmethod def show_menu (): print ('Please select the following functions:') print ('1, Add contact') print ('2, delete contact') print ('3, modify contact information') print ('4, query contact information') print ('5, show all contact information') print ('6, save contact information') print ('7, Exit system') def add_contact (self): name = input ('Please enter your name:') gender = input ('Please enter your gender:') tel = input ('Please enter your phone number:') contact = Contact (name Gender Tel) self.contact_list.append (contact) print (self.contact_list) print (contact) def del_contact (self): del_name = input ('Please enter the contact name to be deleted:') flag=1 for i in self.contact_list: if i.name = = del_name: self.contact_list.remove ( I) flag=0 break if flag==1: print ('check no such person!') Print (self.contact_list) def modify_contact (self): modify_name = input ('Please enter the contact name to be modified:') flag=1 for i in self.contact_list: if i.name = = modify_name: i.name = input ('Please enter contact name:') i.gender = input ('Please enter the contact name:') Contact gender:') i.tel = input ('Please enter the contact phone number:') print (f' modified the contact information successfully Name: {i.name}, gender {i.gender}, mobile number {i.tel}') flag=0 break if flag==1: print ('check no such person!') Def search_contact (self): search_name = input ('Please enter the name of the contact to be queried:') flag=1 for i in self.contact_list: if i.name = = search_name: print (f 'name {i.name}, gender {i.gender} Mobile number {i.tel}') flag=0 break if flag==1: print ('check no such person!') Def show_contact (self): print ("name\ t gender\ t mobile phone number") for i in self.contact_list: print (f'{i.name}\ t {i.gender}\ t {i.tel}') def save_contact (self): F = open ('contact.data') 'w') new_list = [I. Try (new_list)) f.close () def load_contact (self): try: F = open (' contact.data', 'r') except: F = open ('contact.data') 'w') else: data = f.read () new_list = eval (data) self.contact_list = [Contact (I ['name'], I [' gender'], I ['tel']) for i in new_list] finally: f.close () Thank you for your reading The above is the content of "how to achieve the address book system in python". After the study of this article, I believe you have a deeper understanding of how to achieve the address book system in python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.