Day作业

使用一个变量all_students保存一个班的学生信息(4个),每个学生需要保存:姓名、年龄、成绩、电话

all_students = [
    {'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},
    {'name':'stu2', 'age': 29, 'score':90, 'tel':'211222'},
    {'name':'stu3', 'age': 12, 'score':67, 'tel':'521114'},
    {'name':'stu4', 'age': 30, 'score':45, 'tel':'900012'},
] 

1.添加学生:输入学生信息,将输入的学生的信息保存到all_students中

例如输入:
姓名: 小明
年龄: 20
成绩: 100
电话: 111922  
那么就在all_students中添加{'name':'小明', 'age': 20, 'score': 100, 'tel':'111922'}
new_name=input("请输入添加学生姓名:")
new_age=input("请输入添加学生年龄")
new_score=input("请输入添加学生成绩:")
nee_tel=input("请输入添加学生电话:")
new_student={'name':new_name,'age':new_age,'score':new_score,'tel':nee_tel}
all_students.append(new_student)
print(id(all_students))

2.按姓名查看学生信息:

例如输入:
姓名: stu1 就打印:'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'

message=input("请输入查找学生姓名:")
for item in all_students:
    if message==item['name']:
        print(item)

3.求所有学生的平均成绩和平均年龄

age=0
score=0
for item in all_students:
    score+=item['score']
    age+=item['age']
aver_score=score/len(all_students)
aver_age=age/len(all_students)
print(aver_score,aver_age)

4.删除班级中年龄小于18岁的学生

for item in all_students[::]:
    if item['age']<18:
        all_students.remove(item)
print(all_students)

5.统计班级中不及格的学生的人数

count=0
for item in all_students[::]:
    if item['score']<60:
        count=+1
print(count)  

6.打印手机号最后一位是2的学生的姓名

for item in all_students:
     if item['tel'][-1]=='2':
         print(item['name'])
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 使用一个变量all_students保存一个班的学生信息(4个),每个学生需要保存:姓名、年龄、成绩、电话 1.添...
    LittleBear_6c91阅读 231评论 0 1
  • 编写⼀个函数,求1+2+3+...+N 编写⼀个函数,求多个数中的最⼤值 编写⼀个函数,实现摇⾊⼦的功能,打印n个...
    年華盡耗_c24e阅读 128评论 0 0
  • 一、认识Python 1.常用的快捷键 control+/注释的快捷键,添加或取消注释,删除代码可以将代码注释,方...
    烟雨旎旎阅读 204评论 0 0
  • 1.使用位运算判断一个数是否是奇数 注:奇数的二进制的最后一位是1,偶数是0 2.表达式0x13&0x17的值是(...
    憨猜猜阅读 133评论 0 0
  • 8月22日-----字符串相关 2-3 个性化消息: 将用户的姓名存到一个变量中,并向该用户显示一条消息。显示的消...
    future_d180阅读 1,036评论 0 1

友情链接更多精彩内容