Python学习(三)
来源:互联网 发布:深圳cnc编程招聘信息 编辑:程序博客网 时间:2024/05/16 19:16
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]}# 计算平均成绩def average(numbers): total=sum(numbers) total=float(total)/len(numbers) return total #a function called get_average that takes a student dictionary (like lloyd, alice, or tyler) as input and returns his/her weighted average.def get_average(student): homework=average(student["homework"]) quizzes=average(student["quizzes"]) tests=average(student["tests"]) return 0.1*homework+0.3*quizzes+0.6*tests # get_letter_grade function that takes a number score as input and returns a string with the letter grade that that student should receive.def get_letter_grade(score): if score>=90: return "A" elif score >=80: return "B" elif score >=70: return "C" elif score>=60: return "D" else: return "F"print get_letter_grade(lloyd)#get the average for each student and then calculate the average of those averages.def get_class_average(students): results=[] for student in students: results.append(get_average(student)) return average(results) students=[lloyd,alice,tyler]print get_class_average(students)print get_letter_grade(get_class_average(students))//高阶函数调用方式
0 0
- Python学习(三)
- 学习Python (三)
- python 学习(三)
- python学习(三)
- python学习(三)
- python 学习(三)
- python 学习(三)
- python学习(三)
- python学习笔记(三)
- Python学习笔记(三)
- python学习笔记(三)
- python学习笔记:(三)
- Python学习笔记(三)
- Python基础教程学习(三)
- python学习小计(三)
- python学习笔记(三)
- Python学习笔记(三)
- python 学习笔记(三)
- struts-config.xml配置文件详解
- win7中IIS7.0 无法启动的图文教程
- 加盟芋尚爱披萨 实现你的创富梦想!
- 【Android】 Android adb常见问题整理
- C++ GUI Qt 4编程(第二版)
- Python学习(三)
- ECC加密算法入门介绍
- linux 命令的相关网址
- cocos2d-x 中添加显示文字的三种方式 LabelTTF 、LabelBMFont 和 LabelAtlas
- Linux Linux下如何编译并运行C程序
- C++中的继承与虚函数各种概念
- Unity中一些为自己的记录
- Android检测系统的摄像头是否可用
- Android View 与ViewGroup绘制即事件分发机制