Challenge - 5 Problems
Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of code using a function to avoid repetition
What is the output of this code that uses a function to print a greeting twice?
Python
def greet(name): print(f"Hello, {name}!") greet("Alice") greet("Alice")
Attempts:
2 left
๐ก Hint
Look at how many times the greet function is called.
โ Incorrect
The function greet is called twice with the same argument, so it prints the greeting twice.
๐ง Conceptual
intermediate1:30remaining
Why use functions to organize code?
Why do programmers use functions in their code?
Attempts:
2 left
๐ก Hint
Think about how functions help with repeating tasks.
โ Incorrect
Functions help organize code into reusable parts, making it easier to read and maintain.
โ Predict Output
advanced1:30remaining
Output of code without functions causing repetition
What is the output of this code that repeats similar print statements without using a function?
Python
print("Hello, Bob!") print("Hello, Bob!") print("Hello, Bob!")
Attempts:
2 left
๐ก Hint
Count how many print statements there are.
โ Incorrect
The code prints the same greeting three times because there are three print statements.
๐ง Conceptual
advanced1:30remaining
Benefit of functions for changing code easily
How do functions help when you want to change a repeated task in your program?
Attempts:
2 left
๐ก Hint
Think about how many places you need to edit if you use a function.
โ Incorrect
With functions, you only change the code inside the function, and all calls use the updated code.
โ Predict Output
expert2:30remaining
Output of code demonstrating function reuse with different inputs
What is the output of this code that uses a function to greet different people?
Python
def greet(name): return f"Hello, {name}!" messages = [greet("Anna"), greet("Ben"), greet("Cara")] for message in messages: print(message)
Attempts:
2 left
๐ก Hint
Look at the order of names in the list.
โ Incorrect
The function greet is called with different names, and the messages are printed in the same order.