2019-07-30day7作业

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

student_ = {}
name = input('Please input your name:')
age = input('Please input your age:')
score = input('Please input your score')
tel = input('Please input you telephone number:')
gender = input('Please input your gender:')

student_['name'] = name
student_['age'] = age
student_['score'] = score
student_['tel'] = tel
student_['gender'] = gender
print(student_)

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

class_ = []
student = {}
nums = 0
while nums != 6:
    print('\n\n=================student%d====================='%(nums+1))
    names = input('Please input your name:')
    ages = int(input('Please input your age:'))
    scores = int(input('Please input your score'))
    tels = input('Please input you telephone number:')
    genders = input('Please input your gender:')
    student_ = student.copy()
    student_['name'] = names
    student_['age'] = ages
    student_['score'] = scores
    student_['tel'] = tels
    student_['gender'] = genders
    class_.append(student_)
    nums += 1

print('\n\n===================================================================')

reject = []

loser_num = 0
juveniles_num = 0
tel_end_with_8 = []
for student in class_[:]:
    if student['score'] < 60:
        reject.append((student['name'], student['score']))
        loser_num += 1
    if student['age'] < 18:
        juveniles_num += 1
    if int(student['tel'])%10 == 8:
        tel_end_with_8.append(student['name'])
    if not (student['gender'] == 'girl' or student['name'] == 'boy'):
        class_.remove(student)

for j in range(len(class_)-1):
    for i in range(0, len(class_)-j-1):
        if class_[i]['score']<class_[i+1]['score']:
            temp = class_[i-1]
            class_[i-1] = class_[i]
            class_[i] = temp
max_score = class_[0]['name'], class_[0]['score']

print(reject, loser_num, juveniles_num, tel_end_with_8, class_)

3.用三个列表表示三门学科的选课学生姓名(一个学生可以同时选多门课)

a. 求选课学生总共有多少人
b. 求只选了第一个学科的人的数量和对应的名字
c. 求只选了一门学科的学生的数量和对应的名字
d. 求只选了两门学科的学生的数量和对应的名字
e. 求选了三门学生的学生的数量和对应的名字
set_math = {'一护', '鸣人', '银时', '神乐', '有马', '02', '卡卡罗特', '樱满集', '奇犽', '幸村', '五河士道', '和泉纱雾'}
set_chinese = {'金木研', '鸣人', '索隆', '西索', '02', '奇犽', '幸村', '爱德', '乌索普', '一护', '佐助', '龙马', '董香', '尚文'}
set_python = {'鸣人', '亚索', '有马', '三笠', '02', '贝吉塔', '乌索普', '近藤勋', '山本元柳斋', '神乐', '桔梗', '西索', '桐人', '亚丝娜', '尚文'}

n1 = len(set_chinese | set_math | set_python)

set_math_only = set_math - (set_chinese | set_python)
n2 = len(set_math_only)

set_single = set_python ^ set_math ^ set_chinese
n3 = len(set_single)

set_all_subject = set_math & set_chinese & set_python
set_2subjects_only = (set_chinese & set_math) - set_all_subject | (set_python & set_chinese) - set_all_subject | set_python & set_math - set_all_subject
n4 = len(set_2subjects_only)
n5 = len(set_all_subject)

print(n1, (set_math_only, n2), (set_single, n3), (set_2subjects_only, n4), (set_all_subject, n5))
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1,声明一个字典保存一个学生信息,学生信息中包括:姓名,年龄,成绩(单科),电话,性别(男,女,性别不详)2,声明...
    扎克chen阅读 214评论 0 1
  • 1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话、性别(男、女、不明) 2.声...
    Wa_ngli阅读 159评论 0 0
  • 8月22日-----字符串相关 2-3 个性化消息: 将用户的姓名存到一个变量中,并向该用户显示一条消息。显示的消...
    future_d180阅读 999评论 0 1
  • 有感于课中的一个案例: 知道创宇研发技能表中有这样一条叙述: 我们需要对得起名片上的那个头衔:工程师、研究员 作为...
    赵弘阅读 225评论 0 0
  • 今天早晨上班的途中,还有两秒绿灯要变成红灯了!估计自己在两秒的时间走不到马路对面,于是站在路边等下一个绿灯再走! ...
    丽质如兰阅读 177评论 0 1