0
0
Pythonprogramming~15 mins

Keyword arguments in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Keyword Arguments in Python Functions
๐Ÿ“– Scenario: You are creating a simple program to greet people with their name and age. You want to use keyword arguments in a function to make your code clear and flexible.
๐ŸŽฏ Goal: Build a Python function that uses keyword arguments to greet a person by their name and age. You will call this function with keyword arguments to see how it works.
๐Ÿ“‹ What You'll Learn
Create a function called greet that takes two keyword arguments: name and age.
Call the greet function using keyword arguments.
Print the greeting message inside the function.
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Keyword arguments help make your code easier to read and maintain, especially when functions have many parameters.
๐Ÿ’ผ Career
Understanding keyword arguments is important for writing clear and bug-free code in many programming jobs.
Progress0 / 4 steps
1
Define the greet function with keyword arguments
Write a function called greet that takes two keyword arguments: name and age. Inside the function, create a variable message that stores the string: f"Hello, {name}! You are {age} years old."
Python
Need a hint?

Use def greet(*, name, age): to force keyword arguments.

2
Add a print statement inside the greet function
Inside the greet function, add a line to print the message variable.
Python
Need a hint?

Use print(message) to show the greeting.

3
Call the greet function with keyword arguments
Call the greet function using keyword arguments: name="Alice" and age=30.
Python
Need a hint?

Call the function like greet(name="Alice", age=30).

4
Call the greet function with keyword arguments in reverse order
Call the greet function again using keyword arguments but this time with age=25 and name="Bob". Then run the program to see both greetings printed.
Python
Need a hint?

Try calling greet(age=25, name="Bob") to see how keyword arguments allow any order.