Docsity

python programming basic skills, Schemes and Mind Maps of Computer Science

Toggle sidebar
bg1
1/23/23, 3:38 PM
python-for-everybody/wk4 - quiz.py at master · ed-lau/python-for-everybody · GitHub
https://github.com/ed-lau/python-for-everybody/blob/master/wk4 - quiz.py
1/2
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 makes up the function?
You put a # character at the end of the last line of the function
You de-indent a line of code to the same indent level as the def 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 the def keyword
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
Answer:A built-in function
What does the following code print out?
def thing():
print('Hello')
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
What will the following Python code print out?
def func(x) :
print(x)
func(10)
func(20)
10
20
x
10
x
20
x
x
func
func
pf2

Partial preview of the text

Download python programming basic skills and more Schemes and Mind Maps Computer Science in PDF only on Docsity!

1/23/23, 3:38 PM python-for-everybody/wk4 - quiz.py at master · ed-lau/python-for-everybody · GitHub

https://github.com/ed-lau/python-for-everybody/blob/master/wk4 - quiz.py 1/

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 makes up the function? You put a # character at the end of the last line of the function You de-indent a line of code to the same indent level as the def 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 the def keyword

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

Answer:A built-in function

What does the following code print out? def thing(): print('Hello')

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

What will the following Python code print out? def func(x) : print(x)

func(10) func(20) 10 20 x 10 x 20 x x func func

1/23/23, 3:38 PM python-for-everybody/wk4 - quiz.py at master · ed-lau/python-for-everybody · GitHub

https://github.com/ed-lau/python-for-everybody/blob/master/wk4 - quiz.py 2/

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

Answer: print("World")

Question 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 Hello Michael def Michael Hola Bonjour Hello Michael

Answer: Bonjour Michaels

Question 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 - def addtwo(a, b): added = a + b return a

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 lines you must use a function Following the rule that no function can have more than 10 statements in it Avoiding writing the same non-trivial code more than once in your program

Answer: Avoiding writing the same non-trivial code more than once in your program