Code :
# Storing student information
student = list()
# Display a menu
def showMenu():
print("1. Add student information ")
print("2. Delete student information ")
print("3. Modify student information ")
print("4. Show student information ")
print("0. Exit the system ")
select = eval(input(" operation :"))
return select
# Add student information
def addStudent():
print("----- Add student information -----")
name = input(" full name :")
sex = input(" Gender :")
age = input(" Age :")
phone = input(" Telephone :")
student.append({"name":name,"sex":sex,"age":age,"phone":phone})
print(" Add success !")
# Show student information
def showStudent():
if len(student) == 0:
print(" The current student information is empty !")
else:
print("----------- Student information ------------")
print(" Serial number \t full name \t Gender \t Age \t Telephone ")
for i in range(0,len(student)):
print("%d\t%s\t%s\t%s\t%s"%(i+1,student[i].get('name'),student[i].get('sex'),student[i].get('age'),student[i].get('phone')))
print("------------------------------")
# Delete student information
def delStudent():
print("--- Deleting operation in progress ---")
print("----- Current student information ------")
showStudent()
select = eval(input(" Please input the student serial number to delete :"))
del student[select-1]
print(" Delete successful !")
# Modify student information
def reviseStudent():
studict = {1: "name", 2: "sex", 3: "age", 4: "phone"}
print("----- Modification in progress -----")
showStudent()
num = eval(input(" Please input the student serial number to be modified :"))
print("1- Change the name \n2- Change gender \n3- Change the age \n4- Change the phone number ")
revisenum = eval(input(" Please input the serial number of the information to be modified :"))
newstr = input(" Please enter new information :")
student[num-1][studict[revisenum]] = newstr
print(" Modification successful !")
# Main running function
def init():
while True:
# Show student information
showStudent()
# Show menu
select = showMenu()
if select == 1:
addStudent()
elif select == 2:
delStudent()
elif select == 3:
reviseStudent()
elif select == 4:
showStudent()
elif select == 0:
# Exit the system
break
else:
print(" Incorrect input ! Please do it again !")
continue
1. Add student information
2. Delete student information
3. Modify student information
4. Show student information
( More source code 、 Information 、 Courseware 、 Error reporting solutions can be obtained by scanning below )