美文网首页
2019-1-3作业

2019-1-3作业

作者: 白与黑_d83f | 来源:发表于2019-01-03 20:33 被阅读0次

使用一个变量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'}

all_stundent=[]
all_age=[]
all_score=[]
print("请输入学生信息!")
for i in range(4):
     name =input('姓名:')
     age  =int(input('年龄:'))
     score=int(input('分数:'))
     tel  =int(input('电话:'))
     message={'name':name,'age':age,'score':score,'tel':tel}
     all_stundent.append(message)
     all_age.append(age)
     all_score.append(score)
print(all_stundent)

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

例如输入:

姓名: stu1 就打印:'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'
all_stundent=[{'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'},{'name':'stu2','age':19,'score':98,'tel':999999}]

find_stu = input('姓名:')
con=0
for stu in all_stundent:
        if find_stu == stu['name']:
            print('找到了',str(stu)[1:-1])
            con+=1
if con==0:
    print('没有该学生')

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

print('平均分为:%d'%(sum(all_score)/len(all_score)))
print('平均年龄为:%d'%(sum(all_age)/len(all_age)))

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

for index in all_stundent:
    if index['age']<18:
        all_stundent[:].remove(index)
print(all_stundent)

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

sum=0
for index in all_stundent:
    if index['score']<60:
        sum+=1
print('不及格人数为:%d'%sum)

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

for index in all_stundent:
    if index['tel']&1==0:
        print('手机号最后一位是2的是%s'%index['name'])

相关文章

  • 2019-01-03

    2019-1-3的欧盘预测

  • 2019-1-3作业

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

  • 【家庭成长日记】被老师骂

    【2019-1-3星期四 阴】 Mickey有点胆小 早上送孩子上学的路上问Mickey班上有多少同学,因为答应她...

  • 我的桩2019

    2019-1-1 家。古宇湖湖畔站桩20分钟。 2019-1-2 家~宜宾。缺课。 2019-1-3 宜宾~成都。...

  • 2019-1-3

    How Would You Like Your Eggs? (069) A: Wow, you’re up ear...

  • 2019-1-3

    同事抢票的欢呼声拉响了新年的号角,大家都期待着新年的到来,与家人的团聚。而我,只是一如既往地在角落默不出声。 今年...

  • 2019-1-3

    《被讨厌的勇气》也是一本同事极力推荐的书,原以为是一本让人鼓起勇气活出自我,不要害怕被人厌恶的书,看了才发现好...

  • 2019-1-3

    学员:罗杨 体式:三角伸展式 三角转动式 侧角伸展式 侧角转动式 加强前屈伸展式 总结:三角转动式,臀不在一个平面...

  • 2019-1-3

    元气不太足够的一天。身体不太舒服,也觉得劳累。明天要出发去成都,有一场短途旅行,我还没有开心起来。我可能就是对于失...

  • 2019-1-3

    今天和一个全职妈妈聊天,她平时除了接送孩子上下学基本没什么其他事,担心自己会与社会脱节,再加上家里平时没什...

网友评论

      本文标题:2019-1-3作业

      本文链接:https://www.haomeiwen.com/subject/cdazkqtx.html