题目:求平均分
scores = {'语文':89, '数学':95, '英语':80}
知识点:
1-字典.item()
2-global全局变量
3-for循环 分别遍历两个参数
4-自定义函数
d = {'one': 1, 'two': 2, 'three': 3}
print(d.items())
#dict_items([('one', 1), ('two', 2), ('three', 3)])
for key,value in d.items():
print(key+':'+str(value))
#one:1
#two:2
#three:3
scores = {'语文':89, '数学':95, '英语':80}
sum_score = 0
def get_average(scores):
global sum_score
for subject, score in scores.items():
sum_score += score
print('现在的总分是%d'%sum_score)
ave_score = sum_score/len(scores)
print('平均分是%d'%ave_score)
get_average(scores)
网友评论