0
0
Pythonprogramming~15 mins

Multiple return values in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple Return Values in Python
๐Ÿ“– Scenario: You are building a simple program to calculate the area and perimeter of a rectangle. This is useful in many real-life situations like planning a garden or a room.
๐ŸŽฏ Goal: Create a function that returns both the area and perimeter of a rectangle. Then use these values to display the results.
๐Ÿ“‹ What You'll Learn
Create a function that takes two parameters: length and width
The function should return two values: area and perimeter
Call the function with specific length and width values
Print the returned area and perimeter values
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Calculating area and perimeter is common in construction, gardening, and interior design.
๐Ÿ’ผ Career
Understanding how to return multiple values from functions helps in writing clear and efficient code in many programming jobs.
Progress0 / 4 steps
1
Create variables for length and width
Create two variables called length and width and set them to 5 and 3 respectively.
Python
Need a hint?

Think of length and width as the sides of a rectangle.

2
Define a function to calculate area and perimeter
Define a function called calculate_rectangle that takes two parameters: length and width. Inside the function, calculate the area as length * width and the perimeter as 2 * (length + width). Return both area and perimeter.
Python
Need a hint?

Use the return statement to send back both values separated by a comma.

3
Call the function and store returned values
Call the function calculate_rectangle with the variables length and width. Store the returned values in two variables called area and perimeter.
Python
Need a hint?

Use two variables on the left side to receive the two returned values.

4
Print the area and perimeter
Print the values of area and perimeter using two separate print statements.
Python
Need a hint?

Use print(area) and print(perimeter) to show the results.