1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话
message = {'name':'小明','age':'15','score':'90','tel':'1235'}
2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)
a.统计不及格学生的个数
message = [{'name':'小明','age':'15','score':'90','tel':'1235'},
{'name':'小王','age':'18','score':'91','tel':'1237'},
{'name':'小张','age':'19','score':'55','tel':'1234'},
{'name':'小李','age':'22','score':'45','tel':'1236'},
{'name':'小赵','age':'20','score':'77','tel':'1230'},
{'name':'小杨','age':'21','score':'67','tel':'1238'},
{'name':'小马','age':'16','score':'78','tel':'1239'}]
num1 = 0
for index in range(len(message)):
dict1 = message[index]
value1 = dict1['score']
if value1 <= '60':
num1 += 1
print('不及格学生个数:',num1)
b.打印不及格学生的名字和对应的成绩
for index in range(len(message)):
dict1 = message[index]
if dict1['score'] <= '60':
print('不及格学生名字和成绩:',dict1['name'],dict1['score'])
c.统计未成年学生的个数
num1 = 0
for index in range(len(message)):
dict1 = message[index]
if int(dict1['age']) < 18:
num1 += 1
print('未成年学生个数:',num1)
d.打印手机尾号是8的学生的名字
for index in range(len(message)):
dict1 = message[index]
num1 = dict1['tel']
if int(num1)%10 == 8:
print('手机尾号是8的学生的名字;',dict1['tel'])
e.打印最高分和对应的学生的名字
score1 = 0
for index in range(len(message)):
dict1 = message[index]
score2 = int(dict1['score'])
if score2 > score1:
score1 = score2
name1 = dict1['name']
print(name1,score1)
f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)
3.尝试实现学生管理系统的界面(见视频)
list1 = []
while True:
print('=======================================================')
print('**欢迎caoqi.')
print()
print('1. 添加学生')
print('2. 查看学生')
print('3. 修改学生信息')
print('4. 删除学生')
print('5. 返回')
print()
print('=======================================================')
num1 = int(input('请选择(1-5):'))
while num1 == 1:
dict1 ={}
name1 = input('请输入学生姓名:')
dict1['name'] = name1
age1 = input('请输入学生的年龄:')
dict1['age'] = age1
tel1 = input('请输入学生的电话:')
dict1['tel'] = tel1
list1.append(dict1)
print('添加成功')
print('1. 继续')
print('2. 返回')
num1 = int(input('请选择(1-2):'))
if num1 == 2:
num1 = 0
break
while num1 == 2:
print('1. 查看所有学生')
print('2. 按姓名查找')
print('3. 按学号查找')
print('4. 返回')
num2 = 0
while num2 <= 3:
num2 = int(input('请选择(1-4):'))
if num2 == 1:
print(list1)
print('1. 返回')
num2 = 0
else:
if num2 == 4:
break