Complete the code to call the function with a keyword argument.
def greet(name): print(f"Hello, {name}!") greet([1]="Alice")
The function greet expects a keyword argument called name. So we use name="Alice" when calling it.
Complete the function call to use keyword arguments for both parameters.
def describe_pet(animal_type, pet_name): print(f"I have a {animal_type} named {pet_name}.") describe_pet(animal_type=[1], pet_name="Buddy")
The animal_type parameter expects a string value, so we pass it as "dog" with quotes.
Fix the error in the function call by using the correct keyword argument.
def calculate_area(width, height): return width * height area = calculate_area([1]=5, height=10)
length.The function expects width and height as parameters. Using width=5 fixes the error.
Fill both blanks to create a dictionary comprehension that filters and transforms items using keyword arguments.
def filter_items(items, min_price): return {item: price for item, price in items.items() if price [1] min_price} items = {'apple': 5, 'banana': 2, 'cherry': 7} filtered = filter_items(items, min_price=[2])
min_price.The comprehension keeps items with price greater than min_price. We set min_price=3 to filter out cheaper items.
Fill all three blanks to define and call a function using keyword arguments with default values.
def make_coffee(size=[1], sugar=[2], milk=[3]): print(f"Making a {size} coffee with {sugar} sugar and {milk} milk.") make_coffee(size='large', sugar=2, milk='yes')
The function has default values: size='medium', sugar=0, milk='no'. These defaults are used if no arguments are passed.