Lecture 5 Programming
Lecture 5 Programming
3
Outlines
1) Python Function
2) Return statement
4
1
Python Functions
5
Python Functions
➢ As our program grows larger and larger, functions make it more organized and
manageable.
6
Creating Functions
statement(s)
7
Calling a Function
8
Arguments
9
Number of Arguments
▰ By default, a function must be called with the correct number of arguments. Meaning that if
your function expects 2 arguments, you have to call the function with 2 arguments, not
more, and not less. Arguments
10
Number of Arguments
▰ You can also send arguments with the key = value syntax.
Only This way the order of the arguments does not matter.
12
Order of the Arguments
13
2
Return Statement
14
Return Values
15
If not using Return Statement
16
With using Return Statement
▰ Example 1:
17
With using Return Statement
▰ Example 2:
18
With using Return Statement
▰ Example 3:
Compute the area of rectangle .
19
With using Return Statement
▰ Example 4:
Compute the sum of two numbers.
20
With using Return Statement
▰ Example 4:
Compute the sum of two numbers.
21
With using Return Statement
▰ Example 5:
Create a function showEmployee() in such a way that it should accept employee name, and its
salary and display both. If the salary is missing in the function call assign default value 9000 to
salary
22
With using Return Statement
▰ Example 6:
Write a function calculation( ) such that it can accept two variables and calculate the addition and
subtraction of them. And also it must return both addition and subtraction in a single return call
23
Exercise 7
Compute the area of rectangle ,when the user enter Width and Hight of rectangle
24
With using Return Statement
▰ Example 7:
Write a function sum( ) such that it can accept two numbers from the user and calculate the sum of
them. And also it must return addition.
25
THANK YOU
26