首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python 入门教程 十 - Student Becomes the Teacher

2013-09-29 
Python 入门教程 10 ---- Student Becomes the Teacher 第一节1 练习1 设置三个的字典分别为lloyd,alice,t

Python 入门教程 10 ---- Student Becomes the Teacher


 第一节

     1 练习

        1 设置三个的字典分别为lloyd,alice,tyler

        2 对每一个的字典的key都设置为"name","homework" , "quizzes", "tests"

        3 每个字典的key为"name"对应的为人的名字,其他key对应的值为空列表

lloyd = {    "name": "Lloyd",    "homework": [90.0, 97.0, 75.0, 92.0],    "quizzes": [88.0, 40.0, 94.0],    "tests": [75.0, 90.0]}alice = {    "name": "Alice",    "homework": [100.0, 92.0, 98.0, 100.0],    "quizzes": [82.0, 83.0, 91.0],    "tests": [89.0, 97.0]}tyler = {    "name": "Tyler",    "homework": [0.0, 87.0, 75.0, 22.0],    "quizzes": [0.0, 75.0, 78.0],    "tests": [100.0, 100.0]}# students liststudents = [lloyd , alice , tyler]# Add your function below!def average(lst):    sum = 0    for num in lst:        sum = sum+num    return float(sum)/len(lst)# function get_averagedef get_average(stu):    return 0.1*average(stu["homework"])+0.3*average(stu["quizzes"])+0.6*average(stu["tests"])# function get_letter_gradedef get_letter_grade(score):    if(score >= 90):        return "A"    elif(score >= 80 and score < 90):        return "B"    elif(score >= 70 and score < 80):        return "C"    elif(score >= 60 and score < 70):        return "D"    else:        return "F"# function get_class_averagedef get_class_average(class_list):    sum = 0    for stu in class_list:        sum = sum + get_average(stu)    return float(sum)/len(class_list)# print you resultscore = get_class_average(students)print scoreprint get_letter_grade(score



热点排行