Python 入门教程 10 ---- Student Becomes the Teacher
第一节
1 练习
1 设置三个的字典分别为lloyd,alice,tyler
2 对每一个的字典的key都设置为"name","homework" , "quizzes", "tests"
3 每个字典的key为"name"对应的为人的名字,其他key对应的值为空列表
# three dictionaries
lloyd = {"name":"Lloyd" , "homework":[] , "quizzes":[] , "tests":[]}
alice = {"name":"Alice" , "homework":[] , "quizzes":[] , "tests":[]}
tyler = {"name":"Tyler" , "homework":[] , "quizzes":[] , "tests":[]}
第二节
1 练习:把第一个字典lloyd中的三个空列表的值设置对应如下
Homework: 90.0, 97.0, 75.0, 92.0
Quizzes: 88.0, 40.0, 94.0
Test Scores: 75.0, 90.0
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]
}
第三节
1 练习:把lloyd , alice , tyler三个字典放到列表students中
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]
}
# you code here
students = [lloyd , alice , tyler]
第四节
1 练习:按照以下的格式,打印出students列表中的三个字典
Lloyd
[90, 97, 75, 92]
[88, 40, 94]
[75, 90]
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]
}
# you code here
students = [lloyd , alice , tyler]
# you code hrre
for my_list in students:
for str in my_list:
print my_list[str]
第五节
1 练习
1 对于每一个数字列表,我们可以求其平均值,比如 average([0]) #0.0,average([0,2]) #1.0,average([0,1]) #0.5
2 写一个函数average,参数是列表lst,求其平均值并以float形式输出
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]
} # Add your function below!
def average(lst):
sum = 0
for num in lst:
sum = sum+num
return float(sum)/len(lst)
第六节
1 介绍了我们经常需要去求很多数的平均值,比如80 * 0.4 + 86 * 0.6
2 练习:写一个函数get_average,参数是一个学生字典,使用如下比例Homework 10%, quizzes 30% tests60%算出这个学生的平均得分
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]
} # Add your function below!
def average(lst):
sum = 0
for num in lst:
sum = sum+num
return float(sum)/len(lst)
# function get_average
def get_average(stu):
return 0.1*average(stu["homework"])+0.3*average(stu["quizzes"])+0.6*average(stu["tests"])
第七节
1 练习
1 写一个函数get_letter_grade,参数是score,按照以下的规则返回对应的等级
Scores 90 or above: return "A"
If 80 <= score < 90: return "B"
If 70 <= score < 80: return "C"
If 60 <= score < 70: return "D"
If score < 60: return "F"
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]
} # Add your function below!
def average(lst):
sum = 0
for num in lst:
sum = sum+num
return float(sum)/len(lst) # function get_average
def get_average(stu):
return 0.1*average(stu["homework"])+0.3*average(stu["quizzes"])+0.6*average(stu["tests"]) # function get_letter_grade
def 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"
第八节
1 练习:写一个函数get_class_average,参数是班级的列表,求出这个班级所有人的平均值
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]
} # Add your function below!
def average(lst):
sum = 0
for num in lst:
sum = sum+num
return float(sum)/len(lst) # function get_average
def get_average(stu):
return 0.1*average(stu["homework"])+0.3*average(stu["quizzes"])+0.6*average(stu["tests"]) # function get_letter_grade
def 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_average
def get_class_average(class_list):
sum = 0
for stu in class_list:
sum = sum + get_average(stu)
return float(sum)/len(class_list)
第十节
1 练习:打印出students这个班级列表的平均值,然后利用这个值求平均等级
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 list
students = [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_average
def get_average(stu):
return 0.1*average(stu["homework"])+0.3*average(stu["quizzes"])+0.6*average(stu["tests"]) # function get_letter_grade
def 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_average
def 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 result
score = get_class_average(students)
print score
print get_letter_grade(score
Python 入门教程 10 ---- Student Becomes the Teacher的更多相关文章
- 老鸟的Python入门教程
转自老鸟的Python入门教程 重要说明 这不是给编程新手准备的教程,如果您入行编程不久,或者还没有使用过1到2门编程语言,请移步!这是有一定编程经验的人准备的.最好是熟知Java或C,懂得命令行,S ...
- Linux pwn入门教程(10)——针对函数重定位流程的几种攻击
作者:Tangerine@SAINTSEC 本系列的最后一篇 感谢各位看客的支持 感谢原作者的付出一直以来都有读者向笔者咨询教程系列问题,奈何该系列并非笔者所写[笔者仅为代发]且笔者功底薄弱,故无法解 ...
- Python入门教程 超详细1小时学会Python
Python入门教程 超详细1小时学会Python 作者: 字体:[增加 减小] 类型:转载 时间:2006-09-08我要评论 本文适合有经验的程序员尽快进入Python世界.特别地,如果你掌握Ja ...
- Python入门教程 超详细1小时学会Python
Python入门教程 超详细1小时学会Python 本文适合有经验的程序员尽快进入Python世界.特别地,如果你掌握Java和Javascript,不用1小时你就可以用Python快速流畅地写有用的 ...
- python入门(10)使用List和tuple
python入门(10)使用List和tuple list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可 ...
- 2018-06-21 中文代码示例视频演示Python入门教程第五章 数据结构
知乎原链 续前作: 中文代码示例视频演示Python入门教程第四章 控制流 对应在线文档: 5. Data Structures 这一章起初还是采取了尽量与原例程相近的汉化方式, 但有些语义较偏(如T ...
- 2018-06-20 中文代码示例视频演示Python入门教程第四章 控制流
知乎原链 续前作: 中文代码示例视频演示Python入门教程第三章 简介Python 对应在线文档: 4. More Control Flow Tools 录制中出了不少岔子. 另外, 输入法确实是一 ...
- 2018-06-20 中文代码示例视频演示Python入门教程第三章 简介Python
知乎原链 Python 3.6.5官方入门教程中示例代码汉化后演示 对应在线文档: 3. An Informal Introduction to Python 不知如何合集, 请指教. 中文代码示例P ...
- 极度舒适的 Python 入门教程,小猪佩奇也能学会~
编程几乎已经成为现代人的一门必修课,特别是 Python ,不仅长期霸占编程趋势榜.薪资榜第一,还屡屡进入小学教材,甚至成为浙江省信息技术高考项目-- 今天,小编带来了一门极度舒适的 Python 入 ...
随机推荐
- RedHat7笔记
第一章 管理网络 查看网络信息 显示网卡状态# nmcli dev status列出所有连接# nmcli con show只列出可用连接# nmcli con show --active显示网卡配 ...
- Install-User.ps1
Install-User.ps1 function Install-User { param( [Parameter()] [string]$ComputerName = $env:computern ...
- 3G/4G网卡使用
整体架构: pppd call option & ----------↓---------- option脚本(设置PPP连接) ----------↓---------- chat脚本(进行 ...
- 核心运营报表无线端数据,pv,uv相关数据,从9月1号开始就没了,为什么?
问题现象截图 核心运营报表 从获取数据的api的地址可以看出: http://data.51buy.com/json.php?biz=statistic&mod=OrderKeyData&am ...
- PS软件之,快速的修改图片你的尺寸
进入 -- 图像 --- 图像尺寸 -- (前面两个去掉后,只剩下最后一个选项的时候就能够任意的修改图像的尺寸)
- [XML] C# XmlHelper操作Xml文档的帮助类 (转载)
点击下载 XmlHelper.rar 主要功能如下所示 /// <summary> /// 类说明:XmlHelper /// 编 码 人:苏飞 /// 联系方式:361983679 // ...
- 基于shiro授权过程
1.对subject进行授权,调用方法isPermitted("permission串")2.SecurityManager执行授权,通过ModularRealmAuthorize ...
- MvvmCross[翻译] 使用Xamarin与MvvmCross完成一个跨平台App
总览 原文:https://github.com/MvvmCross/MvvmCross/wiki/Tip-Calc-A-first-app 我们所做的第一个Model-View-ViewModel( ...
- hdoj (1162) 最小生成树
Problem B Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Sub ...
- 输出第N个素数
输出第N个素数 public class FindNthPrime { public static void main(String[] args){ int N = Integer.parseInt ...