2.表达式0x13&0x17的值是( 0x13 / 19)
010011 & 010111 = 010011
3.若x=-20,y=3则x&y的结果是( )
-20 = 110100(原) = 101011(反) = 101100(补码)
3 = 000011(补)
101100 & 000011 = 000000(补) = 0
XXXXXXXX XXXXXXXX
00000000 11111111
使用一个变量all_students保存一个班的学生信息(4个),每个学生需要保存:姓名、年龄、成绩、电话
all_students = [
{'name': 'stu1', 'age': 19, 'score': 81, 'tel': '192223'},
{'name': 'stu2', 'age': 29, 'score': 90, 'tel': '211222'},
{'name': 'stu3', 'age': 12, 'score': 67, 'tel': '521114'},
{'name': 'stu4', 'age': 30, 'score': 45, 'tel': '900012'},
{'name': 'stu1', 'age': 30, 'score': 99, 'tel': '192226'}
]
# 1.添加学生:输入学生信息,将输入的学生的信息保存到all_students中
# print('=====添加学生信息======')
# name = input('姓名:')
# age = int(input('年龄:'))
# score = float(input('成绩:'))
# tel = input('电话:')
# student = {'name': name, 'age': age, 'score': score, 'tel': tel}
# # 添加学生
# all_students.append(student)
# print(all_students)
# 2.按姓名查看学生信息:
# 例如输入:
# 姓名: stu1 就打印:'name':'stu1', 'age': 19, 'score':81, 'tel':'192222'
# print('=====查看学生信息======')
# find_name = input('需要查看的学生的姓名:')
# count = 0
# for stu in all_students:
# if stu['name'] == find_name:
# print(str(stu)[1:-1])
# count += 1
#
# if count == 0:
# print('没有该学生!')
# 3.求所有学生的平均成绩和平均年龄
all_ages = 0
all_scores = 0
for stu in all_students:
all_ages += stu['age']
all_scores += stu['score']
print('平均成绩:%.2f 平均年龄:%d' % (all_scores/len(all_students), all_ages/len(all_students)))
# 4.删除班级中年龄小于18岁的学生
# for stu in all_students[:]:
# if stu['age'] < 18:
# all_students.remove(stu)
# print(all_students)
# 5.统计班级中不及格的学生的人数
num = 0
for dict1 in all_students:
if dict1['score'] < 60:
num += 1
print('班级中不及格的学生的人数:%d' % num)
# 6.打印手机号最后一位是2的学生的姓名
for dict1 in all_students:
char = dict1['tel']
if char[-1] == '2':
print(dict1['name'])