程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] implementation of simple address book applet

編輯:Python
 Sub document preparation :
1. ContactMain.py
2. ContactCards.py

 Function list :
1. MainPage()
2. CreatContact()
3. FindContact()
4. CheckAllContact()
5. UpdateContact()

 Compile environment :Ubuntu18.04 Python3 & Pycharm
Shell Please give yourself executable permission to execute ( It can also be explained and implemented directly ), The order is as follows :
chmod -x FileName.py

File1 Code:

#! /usr/bin/python3.6
# Import the add, delete, modify and query toolkit
import ContactCards
# Infinite loop entry function selection
while True:
# Show the home page
ContactCards.MainPage()
# Receive options
OptionKey = input("Input Option:")
if OptionKey in ["1", "2", "3"]:
if OptionKey == "1":
ContactCards.CreatContact()
elif OptionKey == "2":
ContactCards.FindContact()
elif OptionKey == "3":
ContactCards.CheckAllContact()
# sign out
elif OptionKey == "0":
print("Good Bye~~~")
break
# Input error
else:
print("Input option error\n")

File2 Code:

ContactList = []
def MainPage():
""" Home menu """
print("*" * 50)
print("\t\t\t\tContact Management")
print(" ")
print("\t\t\t1. Creat new contact")
print("\t\t\t2. Find a contact")
print("\t\t\t3. Check all contact")
print("\t\t\t0. EXIT")
print("*" * 50)
def CreatContact():
""" Create a new contact """
# Receive all kinds of information
NameTemp = input("Name: ")
PhoneTemp = input("Phone: ")
EmailTemp = input("Email: ")
WechatTemp = input("Wechat: ")
# Insert into contact list
ContactDict = {
"Name": NameTemp, "Phone": PhoneTemp, "Email": EmailTemp, "Wechat": WechatTemp}
ContactList.append(ContactDict)
print("-" * 50)
print("OK! %s Information Add Success!" % ContactDict["Name"])
def FindContact():
"""" Find contacts """
# Receive find contact name
NameTemp = input("Input Find Name: ")
print("-" * 50)
# Traversal search
for Temp in ContactList:
# find
if NameTemp == Temp["Name"]:
print("Find Success")
print("=" * 50)
print("Name\t\tPhone\t\tEmail\t\tWechat")
print("%s\t\t%s\t\t%s\t\t%s" % (Temp["Name"], Temp["Phone"], Temp["Email"], Temp["Wechat"]))
# Modify information options
print("Select: [1]Update [2]Delete [0]Exit")
OptionKey = input("Input Option: ")
# modify , Press enter without modification
if OptionKey == "1":
Temp["Name"] = UpadteContact(Temp["Name"], input("Name(Input Enter No MOdify): "))
Temp["Phone"] = UpadteContact(Temp["Phone"], input("Phone(Input Enter No Modify): "))
Temp["Email"] = UpadteContact(Temp["Email"], input("Email(Input Enter No Modify): "))
Temp["Wechat"] = UpadteContact(Temp["Wechat"], input("Wechat(Input Enter No Modify): "))
print("Update success")
return
# Delete
elif OptionKey == '2':
ContactList.remove(Temp)
print("Delect Success!")
return
# Input 0 Or other
else:
return
# Traversal not found
else:
print("Not Found!")
def CheckAllContact():
""" View all contacts """
# When the contact is empty
if len(ContactList) == 0:
print("Contact List NULL!")
return
# If there are contacts, format the output
print("=" * 50)
print("Name\t\tPhone\t\tEmail\t\tWechat")
for Temp in ContactList:
print("%s\t\t%s\t\t%s\t\t%s" % (Temp["Name"], Temp["Phone"], Temp["Email"], Temp["Wechat"]))
print("Have %d Constct!" % len(ContactList))
def UpadteContact(SourceInfo, UpdateInfo):
""" As a carriage return, the auxiliary function is not modified """
# New information is entered
if len(UpdateInfo) > 0:
return UpdateInfo
# No input detected ( enter )
else:
return SourceInfo

Run a screenshot :


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved