0
0
Pythonprogramming~10 mins

Argument order rules in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to call the function with the correct positional argument.

Python
def greet(name):
    return f"Hello, {name}!"

message = greet([1])
print(message)
Drag options to blanks, or click blank then click option'
A"Alice"
Bname
Cgreet
DHello
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing the function name instead of a string.
Passing a variable that is not defined.
2fill in blank
medium

Complete the function call using a keyword argument.

Python
def describe_pet(pet_name, animal_type='dog'):
    return f"I have a {animal_type} named {pet_name}."

info = describe_pet([1])
print(info)
Drag options to blanks, or click blank then click option'
Aanimal_type='Buddy'
B'Buddy'
Canimal_type='cat'
Dpet_name='Buddy'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Passing only a string without specifying the parameter name.
Using the wrong parameter name.
3fill in blank
hard

Fix the error in the function call by placing arguments in the correct order.

Python
def make_shirt(size, message):
    return f"Shirt size: {size}, message: {message}"

result = make_shirt([1])
print(result)
Drag options to blanks, or click blank then click option'
A'Large', 'Hello World!'
B'Hello World!', 'Large'
Csize='Large', message='Hello World!'
Dmessage='Hello World!', size='Large'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Swapping the order of positional arguments.
Mixing positional and keyword arguments incorrectly.
4fill in blank
hard

Fill both blanks to create a function call with one positional and one keyword argument.

Python
def order_drink(size, flavor):
    return f"Order: {size} {flavor} drink"

order = order_drink([1], [2])
print(order)
Drag options to blanks, or click blank then click option'
A'Medium'
B'Large'
Cflavor='Mango'
Dflavor='Peach'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using keyword argument before positional argument.
Not specifying the keyword argument name.
5fill in blank
hard

Fill all three blanks to call the function with one positional and two keyword arguments in correct order.

Python
def book_flight(destination, seat_class='Economy', meal='Standard'):
    return f"Flight to {destination}, Class: {seat_class}, Meal: {meal}"

confirmation = book_flight([1], [2], [3])
print(confirmation)
Drag options to blanks, or click blank then click option'
A'Paris'
Bseat_class='Business'
Cmeal='Vegetarian'
Ddestination='Paris'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Placing keyword arguments before positional arguments.
Not using parameter names for keyword arguments.