完成一個(gè)控制臺學(xué)生管理系統(tǒng),要求能實(shí)現(xiàn)查看所有學(xué)生的學(xué)號、姓名、年齡、電話,并且能根據(jù)學(xué)號和姓名進(jìn)行查詢,能修改學(xué)生的信息,能刪除學(xué)生信息
all_students = [
{'no':'stu001','name':'stu1','age':18,'phone':'1811111111111'},
{'no':'stu002','name':'stu2','age':20,'phone':'1811111100000'},
{'no':'stu003','name':'stu3','age':22,'phone':'1811111100011'}]
wellcome = """
========================================
歡迎進(jìn)入學(xué)生管理系統(tǒng):
? 1. 添加學(xué)生
? 2. 查看學(xué)生
? 3. 修改學(xué)生信息
? 4. 刪除學(xué)生
? 5. 退出
========================================
請輸入(1-5):
"""
wellcome2 = """
1. 查看所有學(xué)生
2. 按姓名查找
3. 按學(xué)號查找
4. 返回
"""
while True:
menu =int(input(wellcome))
if menu == 1:
sub_menu = 1
while sub_menu != 2:
name = input("請輸入學(xué)生姓名:")
age = input("請輸入學(xué)生年齡:")
phone = input("請輸入學(xué)生電話:")
no = 'stu%03d' % (len(all_students) + 1)
student = {
'no':no,
'name':name,
'age':int(age),
'phone':phone
}
all_students.append(student)
print("添加成功!")
sub_menu =int(input("1. 繼續(xù)\n2. 返回\n請選擇(1-2):"))
elif menu == 2:
sub_menu = int(input(wellcome2))
while sub_menu!=4:
if sub_menu == 1:
for student in all_students:
print("學(xué)號:%s\t姓名:%s\t年齡:%d\t電話:%s" % (student["no"],student["name"],student["age"],student["phone"]))
elif sub_menu == 2:
name = input("請輸入要查找的姓名:")
for student in all_students:
if student["name"]== name:
print("學(xué)號:%s\t姓名:%s\t年齡:%d\t電話:%s" % (student["no"],student["name"],student["age"],student["phone"]))
elif sub_menu == 3:
no = input("請輸入要查找的學(xué)號:")
for student in all_students:
if student["no"]== no:
print("學(xué)號:%s\t姓名:%s\t年齡:%d\t電話:%s" % (student["no"],student["name"],student["age"],student["phone"]))
break
else:
print("查無此人")
sub_menu = int(input(wellcome2))
elif menu == 3:
sub_menu = 1
while sub_menu != 2:
no = input("請輸入要修改的學(xué)生學(xué)號:")
for student in all_students:
if student["no"]== no:
name = input("請輸入學(xué)生姓名:")
age = input("請輸入學(xué)生年齡:")
phone = input("請輸入學(xué)生電話:")
student["name"] = name
student["age"] = int(age)
student["phone"] = phone
break
else:
print("查無此人")
print("修改成功")
sub_menu = int(input("1. 繼續(xù)\n2. 返回\n請選擇(1-2):"))
elif menu == 4:
sub_menu = 1
while sub_menu != 2:
no = input("請輸入要?jiǎng)h除的學(xué)生學(xué)號:")
for student in all_students[:]:
if student["no"]== no:
all_students.remove(student)
break
else:
print("查無此人")
print("刪除成功")
sub_menu = int(input("1. 繼續(xù)\n2. 返回\n請選擇(1-2):"))
else:
print("Bye~")
break