Skip to content

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