文章目录
- 课程简介
- Quiz 4: Functions
- 单选题(1-9)
- 编程题
- Exercise 4.6
课程简介
Python for Everybody 零基础程序设计(Python 入门)
- This course aims to teach everyone the basics of programming computers using Python. 本课程旨在向所有人传授使用 Python 进行计算机编程的基础知识。
- We cover the basics of how one constructs a program from a series of simple instructions in Python. 我们介绍了如何通过 Python 中的一系列简单指令构建程序的基础知识。
- The course has no pre-requisites and avoids all but the simplest mathematics. Anyone with moderate computer experience should be able to master the materials in this course. 该课程没有任何先决条件,除了最简单的数学之外,避免了所有内容。任何具有中等计算机经验的人都应该能够掌握本课程中的材料。
- This course will cover Chapters 1-5 of the textbook “Python for Everybody”. Once a student completes this course, they will be ready to take more advanced programming courses. 本课程将涵盖《Python for Everyday》教科书的第 1-5 章。学生完成本课程后,他们将准备好学习更高级的编程课程。
- This course covers Python 3.
coursera
Python for Everybody 零基础程序设计(Python 入门)
Charles Russell Severance
Clinical Professor
个人主页
Twitter
University of Michigan
课程资源
coursera原版课程-外网
coursera原版视频-中英文精校字幕-B站
Dr. Chuck官方翻录版视频-机器翻译字幕-B站
PY4E-课程配套练习-部分功能需科学上网
Dr. Chuck Online - 系列课程开源官网
Quiz 4: Functions
Take a brief look at how Python implements the ‘store and use later’ programming pattern.
单选题(1-9)
- Which Python keyword indicates the start of a function definition?
- sweet
- def
- break
- help
- In Python, how do you indicate the end of the block of code that makes up the function?
- You de-indent a line of code to the same indent level as the def keyword
- You add the matching curly brace that was used to start the function
- You put a
- You put the “END” keyword in column 7 of the line which is to be the last line of the function
- In Python what is the input() feature best described as?
- A built-in function
- A conditional statement
- A user-defined function
- The central processing unit
- What does the following code print out?
def thing():
print('Hello')
print('There')
- Hello
- defthing
- There
- thingHelloThere
- In the following Python code, which of the following is an “argument” to a function?
x = 'banana'
y = max(x)
print(y)
- x
- max
- ‘banana’
- What will the following Python code print out?
def func(x) :
print(x)
func(10)
func(20)
- 1020
- x10x20
- x20
- funcfunc
- Which line of the following Python program will never execute?
def stuff():
print('Hello')
return
print('World')
stuff()
- def stuff():
- stuff()
- return
- print (‘World’)
- print(‘Hello’)
- What will the following Python program print out?
def greet(lang):
if lang == 'es':
return 'Hola'
elif lang == 'fr':
return 'Bonjour'
else:
return 'Hello'
print(greet('fr'),'Michael')
- HolaBonjourHelloMichael
- defHolaBonjourHelloMichael
- Bonjour Michael
- Hola Michael
- What is the most important benefit of writing your own functions?
- To avoid having more than 10 lines of sequential code without an indent or de-indent
- Avoiding writing the same non-trivial code more than once in your program
- Following the rule that whenever a program is more than 10 lines you must use a function
- Following the rule that no function can have more than 10 statements in it
编程题
Exercise 4.6
题目:
Write a program to prompt the user for hours and rate per hour using input to compute gross pay.
Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours.
Put the logic to do the computation of pay in a function calledcomputepay()
and use the function to do the computation. The function should return a value.
Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should useinput
to read a string andfloat()
to convert the string to a number.
Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
[Desired Output]
Pay 498.75
解题代码:
def computepay(hours, rate): if h <= 40: per = h * r else: per = 40 * r + (h - 40) * r * 1.5 return per hrs = input("Enter Hours:") rat = input("Enter Hourly rate:") h = float(hrs) r = float(rat) p = computepay(h, r) print("Pay", p)