Coursera课程Python for everyone:chapter4

Chapter 4

10 试题

1. 

Which Python keyword indicates the start of a function definition?

def

help

sweet

continue

2. 

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 put the "END" keyword in column 7 of the line which is to be the last line of the function

You add the matching curly brace that was used to start the function }

You put a # character at the end of the last line of the function

3. 

In Python what is the raw_input() feature best described as?

The central processing unit

A built-in function

A reserved word

A user-defined function

4. 

What does the following code print out?

def thing():
    print 'Hello'

print 'There'

There

Hello

Hello

There

thing

Hello

There

5. 

In the following Python code, which of the following is an "argument" to a function?

x = 'banana'
y = max(x)
print y

print

x

y

max

6. 

What will the following Python code print out?

def func(x) :
    print x

func(10)
func(20)

x

10

x

20

10

20

x

20

func

func

7. 

Which line of the following Python program is useless?

def stuff():
    print 'Hello'
    return
    print 'World'

stuff()

def stuff():

return

stuff()

print 'Hello'

print 'World'

8. 

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'

Bonjour Michael

def Michael

Hello Michael

Hola

Bonjour

Hello

9. 

What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug - so read carefully).

def addtwo(a, b):
    added = a + b
    return a

x = addtwo(2, 7)
print x

7

2

14

addtwo

10. 

What is the most important benefit of writing your own functions?

Following the rule that whenever a program is more than 10 lines you must use a function

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 no function can have more than 10 statements in it

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值