001 Python Test
来源:互联网 发布:新淘宝店铺转让价格表 编辑:程序博客网 时间:2024/06/05 07:40
01 Python Test
在Codeacademy上学习Python课程,刷题的笔记记录如下,欢迎交流!
Practice Makes Perfact
- Python Test
- Practice Makes Perfact
- Fun With Numbers
- Practice Practice Practice
- ii Whats the Score 29
- iii Put It Together 39
- iv For the Record 49
- Just Average
- iv Its Okay to be Average 59
- ii Just Weight and See 69
- iii Sending a Letter 79
- iv Part of the Whole 89
- censor
- Fun With Numbers
- Practice Makes Perfact
Fun With Numbers
1. Practice Practice Practice!
题目001:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三>位数?都是多少?
方法1:
num=[1,2,3,4]for i in num: for j in num: if j!=i: for k in num: if (k!=i and k!=j): total =0 total =i*100+j*10+k print total
方法2:
for i in range(1,5): for j in range(1,5): for k in range(1,5): if( i != k ) and (i != j) and (j != k): print i,j,k
ii. What’s the Score? 2/9
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]}
iii. Put It Together 3/9
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 = [lloyd, alice, tyler]
iv. For the Record 4/9
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 = [lloyd, alice, tyler]for x in students: print x['name'] print x['homework'] print x['quizzes'] print x['tests']
Just Average
iv. It’s Okay to be Average 5/9
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(numbers): total = sum (numbers) aver = float(total)/len(numbers) return aver
ii. Just Weight and See 6/9
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(numbers): total = sum (numbers) aver = float(total)/len(numbers) return averdef 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
iii. Sending a Letter 7/9
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(numbers): total = sum (numbers) aver = float(total)/len(numbers) return averdef 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 def get_letter_grade(score): if 90<=score: return "A" elif 80<=score<90: return "B" elif 70<=score<80: return "C" elif 60<=score<70: return "D" else: return "F"get_average(lloyd)
iv. Part of the Whole 8/9
#列表如何作为函数的入口参数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(numbers): total = sum (numbers) aver = float(total)/len(numbers) return averdef 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 def get_letter_grade(score): if 90<=score: return "A" elif 80<=score<90: return "B" elif 70<=score<80: return "C" elif 60<=score<70: return "D" else: return "F" students=["lloyd","alice","tyler"]def get_class_average(students): results=[] for student in students: results.append(get_average(student)) return average(results)
10. censor
#方法1def censor(text, word): x = text.split() for i in range(len(x)): if x[i] == word: x[i] = "*" * len(word) return " ".join(x) #方法2def censor(text, word): if word in text: text = text.replace(word,"*"*len(word)) return text
0 0
- 001 Python Test
- python test
- Selenium+Python Test(一)
- selenium test report (python)
- Python post test
- python test postgresql
- Python---unit test
- python 中的变量-test
- python test framework
- Python Test使用
- python synflood test
- python之Test Suite与Test Runner
- Python nose test framework 介绍
- Python nose test framework 介绍
- Python 中的 unit test 流程
- Python nose test framework 介绍
- Python unittest parametrized test cases
- AKS Primality test (python code)
- ros.launch 文件学习
- Linux内核源码分析-页高速缓存-address_space
- 投票系统UML图
- codevs 1060 搞笑世界杯(DP)
- C#小练习08
- 001 Python Test
- WPF 构建自定义控件 模板Template
- JDBC的再学习
- 七步通过python学习机器学习
- Runtime结合Category给工程中所有控制器替换背景颜色
- nginx重定向规则详细介绍
- codevs 2492 上帝造题的七分钟 2(线段树)
- Javascript异步编程的4种方法
- 主流MySQL集群实现架构优劣势与适用场景分析