Using Python to implement a simple business card management system

Source: Internet
Author: User

Start by creating a new project that contains the main program Cards_main and the tool library Cards_tools:

As follows:

Main function mainly uses while and if to implement 4 function switching, the specific operation of the switch is performed by the function in Cards_tools. Not to mention the code directly, the code is relatively simple:

(1) Cards_main:

*Coding:utf-8 *

"""
File_name:cards_main.py
Author:jack
date:2018.7.18
Function: Business Card management System main program
"""
Import Cards_tools

Use while to implement a window's loop usage

While True:
?? Cards_tools.cards_dis ()
?? Cards_input = input ("Select operation function:")
?? If cards_input in ["1", "2", "3"]:
????? if cards_input = = "1":
???????? Print ("-"20)
???????? Print ("The action code you chose to enter is: 1")
???????? Cards_tools.cards_add ()
????? elif Cards_input = = "2":
???????? Print ("-"
20)
???????? Print ("The action code you chose to enter is: 2")
???????? Cards_tools.cards_show_all ()
????? elif Cards_input = = "3":
???????? Print ("-"20)
???????? Print ("The action code you chose to enter is: 3")
???????? Cards_tools.cards_requ ()
?? elif Cards_input = = "0":
????? Print ("The action code you chose to enter is: 0")
????? Print ("Exiting system ... \ n" "has exited the system, welcome to your next" card management system "!) ")
????? Break
?? Else
????? Cards_input = input ("Input error, please re-enter:")
????? Cards_tools.cards_dis ()
????? #cards_input = input ("Input error, please re-enter:")
????? While True:
???????? Cards_input = input ("Input error, please re-enter:")
???????? Cards_tools.cards_dis ()
???????? If cards_input in ["1", "2", "3", "0"]:
??????????? if cards_input = = "1":
?????????????? Print ("-"
20)
?????????????? Print ("The action code you chose to enter is: 1")
?????????????? Cards_tools.cards_add ()
?????????????? Break
??????????? if cards_input = = "2":
?????????????? Print ("-"20)
?????????????? Print ("The action code you chose to enter is: 2")
?????????????? Cards_tools.cards_show_all ()
?????????????? Break
??????????? if Cards_input = = "3":
?????????????? Print ("-"
20)
?????????????? Print ("The action code you chose to enter is: 3")
?????????????? Cards_tools.cards_requ ()
?????????????? Break
??????????? Else
??????????? # #print ("Back to main Menu")
?????????????? Break
????? Break
(2) Cards_tools:

*Coding:utf-8 *

"""
File_name:cards_main.py
Author:jack
date:2018.7.18
Function: Business card management Systems tools
"""

Show Menu

Def Cards_dis ():
?? "" Show Menu "" "
?? Print (" " 20)
?? Print ("\ t Welcome" card management system V1.0 "\ n"
????? "\t\t\t1. New business card \ n "" \t\t\t2. Show all \ n "" \t\t\t3. Query business card \ n "" \t\t\t0. Exit System ")
?? Print (" " 20)
Cards_list = []

New Business Card

Def cards_add ():
?? "" "New Business Card" ""
?? Print ("-" * 20)
?? Print ("New business Card")
?? "" "input-organize into dictionaries-store dictionary in list-prompt for success" ""
?? NAME_STR = input ("Please enter Name:")
?? GENDER_STR = input ("Please enter Gender:")
?? Tel_int = input ("Please enter Phone:")
?? ADD_STR = input ("Please enter Address:")
?? Cards_dict = {"Name": Name_str,
????????????? "Gender": GENDER_STR,
????????????? "Telephone": Tel_int,
????????????? "Address": Add_str}
?? Cards_list.append (cards_dict)
?? Print (cards_list)
?? Print ("%s's business card added successfully! "% name_str)

Show All

Def cards_show_all ():
?? "" Show All Cards "" "
?? Print ("-" 20)
?? Print ("Show All Business Cards")
?? If Len (cards_list) = = 0:
????? Print ("There is no business card in the current system, please add a business card!" ")
?? Else
????? Print ("="
40)
????? #print ("Name \t\t" "Gender \t\t" "Phone \t\t" "Address")
????? For name in ("Name", "Gender", "phone", "Address"):
???????? Print (name, end= "\t\t")
????? Print ("")
????? For cards_dict in Cards_list:
???????? Print ("%s\t\t%s\t\t%s\t\t%s"% (cards_dict["name"],
???????????????????????????????? cards_dict["Gender"],
???????????????????????????????? cards_dict["Telephone"],
???????????????????????????????? cards_dict["Address"]))
???????? Print (cards_dict)
????? Print ("=" * 40)

Query Business Cards

Def cards_requ ():
?? "" Query Business Card "" "
?? Print ("-" 20)
?? Print ("Query business Card")
?? Find_name = input ("Please enter name to search for:")
?? If Len (cards_list) = = 0:
????? Print ("Sorry! No information was found for user%s, please add! "% find_name)
?? Else
????? For Search_name in Cards_list:
???????? If search_name["name"] = = Find_name:
??????????? Print ("The information for%s was found. "% find_name)
??????????? Print ("="
40)
??????????? For name in ("Name", "Gender", "phone", "Address"):
?????????????? Print (name, end= "\t\t")
??????????? Print ("")
??????????? Print ("s%\t\ts%\t\ts%\t\ts%"% (search_name["name"],
??????????????????????????????????? search_name["Gender"],
??????????????????????????????????? search_name["Telephone"],
??????????????????????????????????? search_name["Address"]))
??????????? Print ("=" * 40)
??????????? Cards_deal (Search_name)
??????????? Break
???????? Else
??????????? Print ("Sorry! No information was found for user%s. "% find_name)

Delete and modify business card information

def cards_deal (find_dict):
?? "" "Modify and delete business card" ""
?? Deal_cards = input ("Choose what you want to do: [1] Delete \t\t[2] Modify \t\t[3] Return to the main menu \ n")
?? If deal_cards in ["1", "2", "3"]:
????? if deal_cards = = "1":
???????? Cards_list.remove (find_dict)
???????? Print ("Delete user%s card successfully!") "% (find_dict[" name "]))
????? if deal_cards = = "2":
???????? find_dict["name"] = Cards_mod (find_dict["name"], "Please enter the modified name:")
???????? find_dict["gender"] = Cards_mod (find_dict["gender"], "Please enter the Modified gender:")
???????? find_dict["Telephone"] = Cards_mod (find_dict["Telephone"], "Please enter the modified phone:")
???????? find_dict["Address" = Cards_mod (find_dict["Address"], "Please enter the modified addresses:")
???????? Print ("User%s's business card modified successfully!") "% find_dict[" name "])
?? Else
???????? Print ("Input error, please re-enter!")
def cards_mod (Cards_value, cards_new):
?? result = input (cards_new)
?? If Len (Result) > 0:
????? return result
?? Else
????? Return Cards_value
I am also a novice, welcome the big boys to criticize correct.

Using Python to implement a simple business card management system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.