I'm studying these days javaweb There are no good cases , This is me a year ago python Answer code written by big homework , Reluctantly took 90 branch , The defense and report are not well written . The teacher's score deduction is relatively serious . Here I send it to beginners to watch , It is also some basic grammar , No database is used . Just completed the operation of adding, deleting, modifying and checking the business card management system according to the operation requirements . But on this basis, I added some new functions , For example, add a loading progress bar 、 And save data in the form of files , etc. . Now I'll talk about it function by function . No material has been sent these days , Turn out the previous code and have a look by the way , Let's review the knowledge , By the way, send it to share with you .
Through the study of this project , Students can learn about the process of color project development , Master project demand analysis 、 Design and function code implementation . Improve students' ability to independently analyze needs and function realization .
Project knowledge : Variable 、 Process control 、 function 、 Inertia block, etc python Common knowledge points in the base . Use python Design a business card management system , Can provide the following services :
1. Program started , Display the welcome interface of the business card management system , And display the function menu .
2. Users use numbers to choose different functions .
3. Choose... According to the function , Execute different kinetic energy .
4. A user's business card needs to record the user's name 、 Telephone 、QQ、 mail .
5. If the specified business card is found , Users can choose to modify or delete business cards .
The first is to load the page , introduce time,time.sleep Every time 0.5 Execute a loop once per second .\r Is the cursor returning to the starting position ,for Cycle each time * many . Less trend execution , It forms a style of progress bar .
import time
def jeimian():# Loading page
print(" Loading business card management system ...".center(50,"="))
m=10
for i in range(m+1):
a="*"*i
b="."*(m-i)
c=i/m*100
print("\r[{}>{}]{:3.0f}%".format(a,b,c),end="")
time.sleep(0.5)
print("")
print(" Loading successful ".center(50,"="))
print("")
This is to be encapsulated and put on the main page main Of while In circulation , Every time the function is executed, it will be shown again , Better interactivity . Of course , In execution while Before the cycle, it should also be displayed once for the user to select the corresponding operation .
def function():# Function page
print(" You have entered the business card management system ".center(50,"="))
print("【1】 New business card ")
print("【2】 Check the business card ")
print("【3】 Delete business card ")
print("【4】 Modify business card ")
print("【5】 Show all business cards ")
print("【6】 Save business card data ")
print("【7】 Exit the system ")
Here is also a set created , Key value pairs used to put user information , Save the information entered by the user , Store a user's information . then b_card_lt=[] It is used to store the information of each user .
def add_B_card():# New business card
print(" You have entered the new business card function ".center(50,"="))
b_card_zd={}
add_name=input(" Please enter the name of the new user :")
add_phone=input(" Please enter the phone number of the new user :")
add_qq=input(" Please enter the new user's qq:")
add_mail=input(" Please enter the email of the new user :")
add_address=input(" Please enter the address of the new user :")
b_card_zd["name"]=add_name
b_card_zd["phone"]=add_phone
b_card_zd["qq"]=add_qq
b_card_zd["mail"]=add_mail
b_card_zd["address"]=add_address
b_card_lt.append(b_card_zd)
print(" User name slice added successfully !!!".center(50,"="))
print("")
After the user enters the user name of the query , use for Loop to find , What you don't find is sum The value of is equal to the length of user information .
def find_B_card():# Check the business card
print(" You have entered the function of querying business cards ".center(50, "="))
print(" Please enter the name of the user's business card you want to query :")
find_name=input()
len1=len(b_card_lt)
sum=0
for i in b_card_lt:
sum+=1
if i["name"]==find_name:
sum-=1
print(" Query results ".center(50,"="))
print(i)
break
if sum==len1:
print(" Query results ".center(50,"="))
print(" There is no user you inquired about in the user business card !".center(50,"*"))
print("")
This is also the first to find , Only when it is found can it be deleted . use remove Method to delete information .
def delete_B_card():# Delete business card
print(" You have entered the delete business card function ".center(50, "="))
print(" Please enter the name of the user business card you want to delete :")
delete_name=input()
len2 = len(b_card_lt)
sum = 0
for i in b_card_lt:
sum += 1
if i["name"] == delete_name:
sum -= 1
print(" Delete result ".center(50, "="))
b_card_lt.remove(i)
print(" Delete successful !".center(50,"="))
break
if sum == len2:
print(" Delete result ".center(50, "="))
print(" There is no user you want to delete in the user business card !".center(50, "*"))
print("")
This is also the first to find , If found, let the user re-enter the modified value , Then assign a new value to the user information to be modified .
def change_B_card():# Modify business card
print(" You have entered the function of modifying business card ".center(50, "="))
print(" Please enter the name of the user business card you want to modify :")
change_neme=input()
len3=len(b_card_lt)
sum=0
for i in b_card_lt:
sum+=1
if i["name"]==change_neme:
sum-=1
new_name=input(" Please re-enter the user's name :")
new_phone=input(" Please re-enter the user's phone :")
new_qq = input(" Please re-enter the user's qq:")
new_mail = input(" Please re-enter the user's email :")
new_address=input(" Please re-enter the user's address :")
i["name"]=new_name
i["phone"]=new_phone
i["qq"]=new_qq
i["mail"]=new_mail
i["address"]=new_address
print(" Modification successful !".center(50,"="))
break
if sum==len3:
print(" Modify the result ".center(50,"="))
print(" There is no user you want to modify in the user business card !".center(50, "*"))
print("")
This is a query , It's very easy for the previous one to understand this .
def show_B_card(): # Show business card
print(" You have entered the function of displaying business cards ".center(50, "="))
print(" All business cards are shown in the table below ".center(50,"="))
k=1
if len(b_card_lt)!=0:
for i in b_card_lt:
print(" The first {} User information :{}".format(k, i))
k += 1
print(" All business cards are displayed ".center(50, "="))
else:
print(" The business card management system has no user business card !".center(50,"="))
print("")
Created a text file , Use the data as write() Method write it in .
def save_to_file():# Save the data
file=open("backup.txt","w")
file.write(str(b_card_lt))
file.close()
print(" The business card data has been saved successfully ".center(50,"="))
print("")
This is the data of the last operation if it is run next time , Data will be protected , Load data first when running .
def recover_data():# Restore data
global b_card_lt
file=open("backup.txt")
content=file.read()
b_card_lt=eval(content)
file.close()
1. First call recover_data()、jeimian() function , The above recovery data and progress bar .
2. Then call the function page function circularly .
3. Let the user choose the function to operate
4. Jump to the corresponding function to execute
5. Finally, the user exit judgment and interaction effect .
import card_system
b_card_lt=[]
card_system.recover_data()
card_system.jeimian()
print(" Welcome to use 【 Business card management system 】V1.0".center(50,"="))
while True:
card_system.function()
choice = input(" Please enter a number 1~7 Indicates the operation you want to perform :")
if choice in ['1', '2', '3', '4', '5', '6', '7']:
if choice == '1':
card_system.add_B_card()
elif choice == '2':
card_system.find_B_card()
elif choice == '3':
card_system.delete_B_card()
elif choice == '4':
card_system.change_B_card()
elif choice == '5':
card_system.show_B_card()
elif choice == '6':
card_system.save_to_file()
elif choice == '7':
print(" Are you sure you want to exit the business card management system ?".center(50, "="))
choice1 = input(" Please enter yes/no:")
if choice1 in ['yes', 'no']:
if choice1 == 'yes':
print(" Thank you for using the business card management system ,See you!".center(50, "="))
break
else:
print(" Your input is illegal , Please re-enter ".center(50, "*"))
else:
print(" Your input is illegal , Please re-enter ".center(50, "*"))
import time
def jeimian():# Loading page
print(" Loading business card management system ...".center(50,"="))
m=10
for i in range(m+1):
a="*"*i
b="."*(m-i)
c=i/m*100
print("\r[{}>{}]{:3.0f}%".format(a,b,c),end="")
time.sleep(0.5)
print("")
print(" Loading successful ".center(50,"="))
print("")
def function():# Function page
print(" You have entered the business card management system ".center(50,"="))
print("【1】 New business card ")
print("【2】 Check the business card ")
print("【3】 Delete business card ")
print("【4】 Modify business card ")
print("【5】 Show all business cards ")
print("【6】 Save business card data ")
print("【7】 Exit the system ")
def add_B_card():# New business card
print(" You have entered the new business card function ".center(50,"="))
b_card_zd={}
add_name=input(" Please enter the name of the new user :")
add_phone=input(" Please enter the phone number of the new user :")
add_qq=input(" Please enter the new user's qq:")
add_mail=input(" Please enter the email of the new user :")
add_address=input(" Please enter the address of the new user :")
b_card_zd["name"]=add_name
b_card_zd["phone"]=add_phone
b_card_zd["qq"]=add_qq
b_card_zd["mail"]=add_mail
b_card_zd["address"]=add_address
b_card_lt.append(b_card_zd)
print(" User name slice added successfully !!!".center(50,"="))
print("")
def find_B_card():# Check the business card
print(" You have entered the function of querying business cards ".center(50, "="))
print(" Please enter the name of the user's business card you want to query :")
find_name=input()
len1=len(b_card_lt)
sum=0
for i in b_card_lt:
sum+=1
if i["name"]==find_name:
sum-=1
print(" Query results ".center(50,"="))
print(i)
break
if sum==len1:
print(" Query results ".center(50,"="))
print(" There is no user you inquired about in the user business card !".center(50,"*"))
print("")
def delete_B_card():# Delete business card
print(" You have entered the delete business card function ".center(50, "="))
print(" Please enter the name of the user business card you want to delete :")
delete_name=input()
len2 = len(b_card_lt)
sum = 0
for i in b_card_lt:
sum += 1
if i["name"] == delete_name:
sum -= 1
print(" Delete result ".center(50, "="))
b_card_lt.remove(i)
print(" Delete successful !".center(50,"="))
break
if sum == len2:
print(" Delete result ".center(50, "="))
print(" There is no user you want to delete in the user business card !".center(50, "*"))
print("")
def change_B_card():# Modify business card
print(" You have entered the function of modifying business card ".center(50, "="))
print(" Please enter the name of the user business card you want to modify :")
change_neme=input()
len3=len(b_card_lt)
sum=0
for i in b_card_lt:
sum+=1
if i["name"]==change_neme:
sum-=1
new_name=input(" Please re-enter the user's name :")
new_phone=input(" Please re-enter the user's phone :")
new_qq = input(" Please re-enter the user's qq:")
new_mail = input(" Please re-enter the user's email :")
new_address=input(" Please re-enter the user's address :")
i["name"]=new_name
i["phone"]=new_phone
i["qq"]=new_qq
i["mail"]=new_mail
i["address"]=new_address
print(" Modification successful !".center(50,"="))
break
if sum==len3:
print(" Modify the result ".center(50,"="))
print(" There is no user you want to modify in the user business card !".center(50, "*"))
print("")
def show_B_card(): # Show business card
print(" You have entered the function of displaying business cards ".center(50, "="))
print(" All business cards are shown in the table below ".center(50,"="))
k=1
if len(b_card_lt)!=0:
for i in b_card_lt:
print(" The first {} User information :{}".format(k, i))
k += 1
print(" All business cards are displayed ".center(50, "="))
else:
print(" The business card management system has no user business card !".center(50,"="))
print("")
def save_to_file():# Save the data
file=open("backup.txt","w")
file.write(str(b_card_lt))
file.close()
print(" The business card data has been saved successfully ".center(50,"="))
print("")
def recover_data():# Restore data
global b_card_lt
file=open("backup.txt")
content=file.read()
b_card_lt=eval(content)
file.close()
import card_system
b_card_lt=[]
card_system.recover_data()
card_system.jeimian()
print(" Welcome to use 【 Business card management system 】V1.0".center(50,"="))
while True:
card_system.function()
choice = input(" Please enter a number 1~7 Indicates the operation you want to perform :")
if choice in ['1', '2', '3', '4', '5', '6', '7']:
if choice == '1':
card_system.add_B_card()
elif choice == '2':
card_system.find_B_card()
elif choice == '3':
card_system.delete_B_card()
elif choice == '4':
card_system.change_B_card()
elif choice == '5':
card_system.show_B_card()
elif choice == '6':
card_system.save_to_file()
elif choice == '7':
print(" Are you sure you want to exit the business card management system ?".center(50, "="))
choice1 = input(" Please enter yes/no:")
if choice1 in ['yes', 'no']:
if choice1 == 'yes':
print(" Thank you for using the business card management system ,See you!".center(50, "="))
break
else:
print(" Your input is illegal , Please re-enter ".center(50, "*"))
else:
print(" Your input is illegal , Please re-enter ".center(50, "*"))
Here is also finished ,Python Language is relatively easy to understand , So I just said the general idea , The specific operations inside are all in English, and there should be no problem . And this is also my big homework a year ago , If you are interested, you can add id lookup 、 Modification and other functions . I'm studying these days javaweb, I'll make a few cases to share with you when I'm almost finished learning .