0
0
Pythonprogramming~15 mins

Positional arguments in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Positional Arguments in Python Functions
๐Ÿ“– Scenario: You are creating a simple calculator program that adds two numbers. You will use a function that takes two numbers as inputs and returns their sum.
๐ŸŽฏ Goal: Build a Python function that uses positional arguments to add two numbers and print the result.
๐Ÿ“‹ What You'll Learn
Create a function named add_numbers that takes exactly two positional arguments named num1 and num2.
Call the function add_numbers with two numbers as positional arguments.
Print the result returned by the function.
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Functions with positional arguments are used everywhere in programming to perform tasks with inputs, like calculators, data processing, and more.
๐Ÿ’ผ Career
Understanding how to define and call functions with positional arguments is a fundamental skill for any programming job.
Progress0 / 4 steps
1
Create the function with two positional arguments
Write a function named add_numbers that takes two positional arguments called num1 and num2. Inside the function, return the sum of num1 and num2.
Python
Need a hint?

Define the function with two names inside the parentheses. Use return to send back the sum.

2
Call the function with two numbers
Call the function add_numbers with the positional arguments 5 and 7, and store the result in a variable named result.
Python
Need a hint?

Use the function name followed by parentheses with two numbers inside, separated by a comma.

3
Print the result
Write a print statement to display the value stored in the variable result.
Python
Need a hint?

Use print(result) to show the sum on the screen.

4
Test with different numbers
Call the function add_numbers again with the positional arguments 10 and 20, store the result in result, and print it.
Python
Need a hint?

Call the function with new numbers and print the result again to see the new sum.