Chapter 4 :Programming for Everybody (Getting Started with Python) (Python for Everybody Specialization) Answers 2025
Question 1
Which Python keyword indicates the start of a function definition?
β
def
β return
β continue
β rad
π§ Explanation:
Functions in Python are always defined using the def keyword.
Example:
def greet():
print("Hello")
Question 2
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 level as the def keyword
β Add 10 dashes
β Put : in first column
β Add }
π§ Explanation:
Python uses indentation (not braces {}) to define code blocks. When you de-indent, the function ends.
Question 3
In Python, what is the input() feature best described as?
β
A built-in function
β CPU
β User-defined function
β Conditional statement
π§ Explanation:input() is a built-in function that pauses the program and waits for user input.
Question 4
What does this code print?
def thing():
print('Hello')
print('There')
thing()
β
There
Hello
β thing
β def thing
β thing Hello There
π§ Explanation:
The function is defined first, but not executed until thing() is called.
Question 5
Which of the following is an “argument” to a function?
β
‘banana’
β x
β max
β y
π§ Explanation:
In the line y = max(x), the argument passed into the function max() is 'banana'.
Question 6
What will this code print out?
def func(x):
print(x)
func(10)
func(20)
β
10
20
β x x
β def x func func
β x 20
π§ Explanation:
The function prints whatever value is passed in each time itβs called.
Question 7
Which line will never execute?
def stuff():
print('Hello')
return
print('World')
stuff()
β
print('World')
β return
β def stuff():
β stuff()
β print(‘Hello’)
π§ Explanation:
Once Python executes a return, it exits the function immediately.
Everything after it is ignored.
Question 8
What will this code print?
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
π§ Explanation:
The function returns 'Bonjour' for 'fr', and then 'Michael' is printed beside it.
Question 9
What does this code print?
def addtwo(a, b):
added = a + b
return a
x = addtwo(2, 7)
print(x)
β
2
β 9
β 14
β 7
π§ Explanation:
Even though added = a + b is calculated, the function returns a, not added.
So the output is 2.
Question 10
What is the most important benefit of writing your own functions?
β
Avoiding writing the same non-trivial code more than once in your program
β No function over 10 lines
β No 10-line code blocks
β Must use function after 10 lines
π§ Explanation:
Functions promote code reuse, organization, and readability β helping avoid repetition.
π§Ύ Summary Table
| Q# | β Correct Answer | Key Concept |
|---|---|---|
| 1 | def | Function definition keyword |
| 2 | De-indent | Function block ending |
| 3 | Built-in function | input() type |
| 4 | There / Hello | Function call order |
| 5 | ‘banana’ | Function argument |
| 6 | 10 / 20 | Passing parameters |
| 7 | print(‘World’) | return stops execution |
| 8 | Bonjour Michael | Function return values |
| 9 | 2 | Return statement behavior |
| 10 | Avoid code repetition | Function benefit |