day6作业 (1)

1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话、性别(男、女、不明)

student = {'name': '任欣康', 'age': 23, 'score': 100, 'tel': '10086', 'sex': '男'}
print(student)

2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)
a.统计不及格学生的个数
b.打印不及格学生的名字和对应的成绩
c.统计未成年学生的个数
d.打印手机尾号是8的学生的名字
e.打印最高分和对应的学生的名字
f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)

​ g.删除性别不明的所有学生

student = [
{'name': '任欣康', 'age': 23, 'score': 54, 'tel': '10054789646', 'sex': '不明'},
{'name': '谭言飞', 'age': 18, 'score': 45, 'tel': '10055555586', 'sex': '男'},
{'name': '武则天', 'age': 90, 'score': 75, 'tel': '10555555088', 'sex': '女'},
{'name': '周瑜', 'age': 32, 'score': 56, 'tel': '15655555546', 'sex': '不明'},
{'name': '廉颇', 'age': 14, 'score': 89, 'tel': '10085555555', 'sex': '男'},
{'name': '小乔', 'age': 61, 'score': 74, 'tel': '10054444468', 'sex': '女'}
]
scores = 0
c = 0
max_score = 0
max_name = '随便'
# a
for a in student:
    if a['score'] < 60:
        scores += 1
print('不及格的学生人数是:',scores)
# b
for a in student:
    if a['score'] < 60:
        print('不及格', a['name'],a['score'])
# c
for a in student:
    if a['age'] < 18:
        c += 1
print('未成年人的个数是:', c)
# d
for a in student:
    if int(a['tel'][-1] ) == 8:
        print('手机尾号是8的学生的名字是:', a['name'])
# e
for a in student:
    if a['score'] > max_score:
        max_score = a['score']
        max_name = a['name']
print(max_score, max_name)
# f


# g
for a in student:
    if a['sex'] == '不明':
        student.remove(a)
print('删除性别不明的人后的列表:',student)

3.用三个列表表示三门学科的选课学生姓名(一个学生可以同时选多门课)
a. 求选课学生总共有多少人
b. 求只for选了第一个学科的人的数量和对应的名字
c. 求只选了一门学科的学生的数量和对应的名字
d. 求只选了两门学科的学生的数量和对应的名字
e. 求选了三门学生的学生的数量和对应的名字

a = ['言飞', '拉拉', '佳佳', '嘎嘎', '大大', '胖胖', '居居']
b = ['佳佳', '嘻嘻', '哈哈', '言飞', '大大', '小小' '东东']
c = ['言飞', '啦啦', '痘痘', '佳佳']
list1 = a+b+c
sum1 = 0
sum2 = 0
# a
d = []
for num in list1:
    if num not in d:
        d.append(num)
print('选课人数为',len(d))


# b
for num in a:
    if num not in b and num not in c:
        sum2 += 1
        print('只选了第一门课的人:',num)
print('人数为:',sum2)
# c.
for num in list1:
    if list1.count(num) == 1:
        sum1 +=1
        print(num, end=',')
print('选一门课的人数为:', sum1)

# d
d = []
for num in list1:
    if list1.count(num) == 2 and num not in d:
        d.append(num)
        print(num)
print('选两门课的人数为:',len(d))

# e.
d = []
for num in list1:
    if list1.count(num) == 3 and num not in d:
        d.append(num)
        print(num)
print('选三门课的人数为:',len(d))


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值