0
0
Pythonprogramming~15 mins

Argument order rules in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Argument order rules
๐Ÿ“– Scenario: Imagine you are creating a simple program to greet people with their name and age. You want to learn how to write functions with different types of arguments in the right order.
๐ŸŽฏ Goal: You will build a function that takes arguments in the correct order: positional, default, and keyword-only arguments. Then you will call this function correctly to print a greeting message.
๐Ÿ“‹ What You'll Learn
Create a function with one positional argument called name
Add one default argument called age with default value 30
Add one keyword-only argument called city without a default
Call the function with correct argument order and print the greeting
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Functions with clear argument order are used in real programs to avoid confusion and bugs when many options are needed.
๐Ÿ’ผ Career
Understanding argument order is important for writing clean, maintainable code in any software development job.
Progress0 / 4 steps
1
Create the greeting function with positional and default arguments
Define a function called greet that takes one positional argument name and one default argument age set to 30. Inside the function, write a print statement that says: "Hello {name}, you are {age} years old."
Python
Need a hint?

Remember, positional arguments come first, then default arguments with an equals sign.

2
Add a keyword-only argument called city
Modify the greet function to add a keyword-only argument called city after a * symbol. Inside the function, update the print statement to say: "Hello {name} from {city}, you are {age} years old."
Python
Need a hint?

Use * to mark the start of keyword-only arguments.

3
Call the greet function with correct argument order
Write a call to the greet function with name as "Alice", age as 25, and city as "Paris". Use positional arguments for name and age, and keyword argument for city.
Python
Need a hint?

Remember to pass city as a keyword argument after the *.

4
Print the greeting message
Run the program and print the greeting message from the greet function call.
Python
Need a hint?

The function call already prints the greeting. Just run the program.