Chapter Practice Arena
All ChaptersFunctions Problems
Targeted practice challenges specifically curated for this chapter. Inspect hints, verify outputs, and check Pythonic solutions.
Difficulty:
Chapter:
Showing 6 challenges · 20 total · Page 1 of 4
Write a function named announce() that prints Done but has no return statement. Store the result of announce() in result, then print result. Predict the exact output.
Starter Code
# Define announce(), call it, and print its result
Expected Output:Done
None
Define double(n) so that it returns n multiplied by 2. Call double(6), store the returned value in result, and print result.
Starter Code
# Define double(n), call it with 6, and print the result
Expected Output:12
Define greet(name) so that it prints Hi, followed by the supplied name. Call it using the keyword argument name='Sam'.
Starter Code
# Define greet(name) and call it with name='Sam'
Expected Output:Hi, Sam
The call describe(name='Ira', 'Delhi') is invalid because a positional argument follows a keyword argument. Given the definition def describe(name, city): that prints the sentence 'Ira lives in Delhi.' when called with these values, rewrite the call correctly using one positional argument and one keyword argument.
Starter Code
def describe(name, city):
print(f'{name} lives in {city}.')
# Write the corrected function call below
Expected Output:Ira lives in Delhi.
Write the following program and explain why its output appears in this order: the program prints Start, displays 7 from the function call, and finally prints End.
Starter Code
# Define show_number(number), then print Start, # call show_number(7), and print End
Expected Output:Start
7
End
Complete add_item(item, items=None) so it creates a new list when items is None, appends item, and returns the list. Print the results of add_item('pen') and add_item('book').
Starter Code
def add_item(item, items=None):
# Create a list when items is None
# Append item and return the list
pass
print(add_item('pen'))
print(add_item('book'))Expected Output:['pen']
['book']