WEBVTT

00:00.000 --> 00:05.000
Advanced functions, parameters and return values.

00:05.000 --> 00:09.000
In this video, we will understand how to use function parameters,

00:09.000 --> 00:12.000
learn how to return multiple values from a function,

00:12.000 --> 00:17.000
and use loops to allow repeated execution of the program.

00:17.000 --> 00:22.000
This program helps us calculate the area and perimeter of different shapes.

00:22.000 --> 00:25.000
We use it to understand how functions take parameters,

00:25.000 --> 00:29.000
process values, and return results for further use.

00:30.000 --> 00:32.000
Define a function.

00:32.000 --> 00:36.000
The program defines a function, calculate polygon sides

00:36.000 --> 00:40.000
that takes one parameter sides to determine the type of shape.

00:40.000 --> 00:46.000
Inside the function, if sides equals to zero, it prints no polygon,

00:46.000 --> 00:52.000
and returns, none common none, means no calculations.

00:52.000 --> 00:55.000
Else if, sides equal to three.

00:55.000 --> 00:58.000
Triangle, the user enters three side lengths,

00:58.000 --> 01:05.000
and the function calculates, perimeter equal to sum of all three sides.

01:05.000 --> 01:13.000
Area equal to base into height divided by two, assuming two sides form the base and height.

01:13.000 --> 01:16.000
Else if, sides equals to four.

01:16.000 --> 01:22.000
If the user enters four, they are prompted to choose between a square, s, or rectangle,

01:23.000 --> 01:26.000
R, and then enter required values.

01:26.000 --> 01:31.000
However, if the user enters a number other than zero, three, or four,

01:31.000 --> 01:35.000
the program displays a message, invalid number of sides.

01:35.000 --> 01:39.000
Please enter zero, three, or four.

01:39.000 --> 01:43.000
In all valid cases, the function calculates and returns the area and perimeter

01:43.000 --> 01:47.000
as a tuple containing both values.

01:47.000 --> 01:50.000
Handling user input.

01:50.000 --> 01:53.000
The program asks for user input.

01:53.000 --> 01:56.000
Use input function to decide which shape they want to calculate.

01:56.000 --> 02:01.000
It converts numerical inputs using float to ensure calculations work correctly.

02:01.000 --> 02:09.000
For four sided shapes, it asks the user to choose between square or rectangle before taking inputs.

02:09.000 --> 02:12.000
Using a loop to repeat the program.

02:12.000 --> 02:17.000
The main function contains a while-true loop, ensuring the program runs continuously

02:17.000 --> 02:20.000
until the user decides to stop.

02:20.000 --> 02:23.000
It calls, calculate polygon's sides function,

02:23.000 --> 02:27.000
stores the returned values, and displays them.

02:27.000 --> 02:32.000
The loop continues until the user enters no when asked if they want to continue.

02:32.000 --> 02:36.000
Understanding return values.

02:36.000 --> 02:41.000
The program checks if the returned values are not none before printing them.

02:41.000 --> 02:46.000
If valid, it displays, area and perimeter, using print function.

02:46.000 --> 02:50.000
Since the function returns values instead of printing them,

02:50.000 --> 02:53.000
the main program can use these values flexibly.

02:53.000 --> 02:57.000
After every calculation, the user is asked if they want to continue.

02:57.000 --> 03:03.000
If they enter no, the program thanks them and exits.

03:03.000 --> 03:07.000
This program teaches the importance of parameters and return values,

03:07.000 --> 03:12.000
helping students understand how functions can process and return useful data

03:12.000 --> 03:15.000
for further use in Python programs.

