Address book management system 3.0 Mainly to train students to python Function call 、 Use of time function 、 The use of font colors and python Application and exit of dead cycle
python Student address book management system of basic project practice 1.0
python Student address book management system of basic project practice 2.0
Function module analysis
1. home page ( Menu functions )
2. Add student information
3. Delete student information
4. View student information
5. Get all student information
6. Exit the system
The code is as follows :
import time
students = [{'id': '100', ' full name ': ' Li Hua ', ' Gender ': ' male ', 'mobile': '1008611'},
{'id': '199', ' full name ': ' Han Meimei ', ' Gender ': ' Woman ', 'mobile': '13215'}]
student = {}
def title():
print("=" * 50)
print(' \033[1;31m Welcome to the address book system 3.0\033[0m')
print(' \033[1;34m[1]\033[0m \033[1;32m Add student information \033[0m')
print(' \033[1;34m[2]\033[0m \033[1;32m Delete student information \033[0m')
print(' \033[1;34m[3]\033[0m \033[1;32m View all student information \033[0m')
print(' \033[1;34m[4]\033[0m \033[1;32m View personal student information \033[0m')
print(' \033[1;34m[5]\033[0m \033[1;32m Exit the student system \033[0m')
print("=" * 50)
def add():
student["id"] = input(" Please enter the student number :")
student[" full name "] = input(" Please enter a name :")
student[" Gender "] = input(" Please enter gender :")
student["mobile"] = input(" Please enter the phone number :")
print(" Saving .....")
time.sleep(1)
print(" Saved successfully !")
time.sleep(0.5)
students.append(student)
def delete():
x = input(" Please enter the student ID to delete :")
flag = 0
for i in students:
if x == i["id"]:
del i
time.sleep(1)
print(" Delete successful !")
flag = 1
break
if (flag == 0):
print("\033[1;31m I'm sorry , No student information found !\033[0m")
return flag
def findAll():
for m in students:
print(f'\033[1;35m Student number :{m["id"]}\t full name :{m[" full name "]}\t Gender :{m[" Gender "]}\t\tmobile:{m["mobile"]}\033[0m')
def findOne():
x = input(" Please enter the student ID you want to find :")
flag = 0
for i in students:
if x == i["id"]:
time.sleep(1)
print(f'\033[1;35m Student number :{i["id"]}\t full name :{i[" full name "]}\t Gender :{i[" Gender "]}\t\tmobile:{i["mobile"]}\033[0m')
flag = 1
break
if (flag == 0):
print("\033[1;31m I'm sorry , No student information found !\033[0m")
return flag
while True:
title()
num = int(input(" Please enter the operation you want to perform :"))
if num == 1:
time.sleep(1)
add()
elif num == 2:
time.sleep(1)
a = delete()
if (a == 0):
for b1 in range(3, 0, -1):
time.sleep(0.5)
print("————\033[1;34m Do you have {} Second chance \033[0m————".format(b1))
if delete() == 1:
time.sleep(1)
break
elif num == 3:
print(" Trying to load student information ...")
time.sleep(1)
findAll()
print(" Loading complete .")
time.sleep(0.5)
elif num == 4:
time.sleep(1)
c = findOne()
if (c == 0):
for b1 in range(3, 0, -1):
time.sleep(0.5)
print("————\033[1;34m Do you have {} Second chance \033[0m————".format(b1))
if findOne() == 1:
time.sleep(1)
break
elif num == 5:
time.sleep(1)
print(" Thank you for using !!")
break
else:
print(" Input command error , Please re-enter the instruction !")
time.sleep(1)
figure :