Python For EveryBody
Python For EveryBody
Question
1
Which Python keyword indicates the start of a function
definition?
help
rad
break
def
Answer: def
Question 2
In Python, how do you indicate the end of the block of code that
keyword
You add a line that has at least 10 dashes
You put the colon character (:) in the first column of a line
Answer: You de-indent a line of code to the same indent level as
Question 3
In Python what is the raw_input() feature best described as?
A conditional statement
A data structure that can hold multiple values using strings as
keys
A built-in function
A reserved word
print 'There'
thing
Hello
There
There
Hello
def
thing
Answer: There
Question 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
x
print
max
Answer: x
func(10)
func(20)
10
20
x
10
x
20
x
x
func
func
Answer: 10 20
Question 7
Which line of the following Python program is useless?
def stuff():
print 'Hello'
return
print 'World'
stuff()
print 'Hello'
def stuff():
stuff()
print 'World'
return
print greet('fr'),'Michael'
Bonjour Michael
Hello Michael
def Michael
Hola
Bonjour
Hello
Michael
is a bit of a trick question and the code has what many would
x = addtwo(2, 7)
print x
addtwo
2
9
Traceback
Answer: 2
Question 10
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
Following the rule that whenever a program is more than 10
statements in it
Avoiding writing the same non-trivial code more than once in
your program