0% found this document useful (0 votes)
4 views

Class VIII Chapter 3 Functions in Depth

The document explains functions in programming, detailing their definition, syntax, advantages, and examples of usage. It also compares the print function and return keyword, highlighting their differences. Additionally, it includes exercises to reinforce understanding of functions and their benefits in programming.

Uploaded by

vandana.ratnam81
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Class VIII Chapter 3 Functions in Depth

The document explains functions in programming, detailing their definition, syntax, advantages, and examples of usage. It also compares the print function and return keyword, highlighting their differences. Additionally, it includes exercises to reinforce understanding of functions and their benefits in programming.

Uploaded by

vandana.ratnam81
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

KENDRIYA VIDYALAYA SECL NOWROZABAD

SUBJECT : COMPUTER
CHAPTER 3 : FUNCTIONS IN DEPTH

* Function : A function is a block of code made up of a set of steps that results


in a single specific action.

* Syntax of Function : # parameter (s)


def function_name ( ) : # Function Initialization or definition
statement 1 # Function Body
statement 2 # Function Body
print ( ) # Function Body
function_name ( ) # Function call
# argument (s)
* Advantages of using Functions :
1. Increases readability : makes code organized and easy to understand.
2. Reduces code length: redundant code is removed and replaced by
functions.
3. Reusability: Code reusability increases.

Q. Write a programme to print sum of two numbers using function.


Code: def add (a,b):
sum = a+b
print (sum)
add (5,8)
Output : 13

Q. Write a programme to print area of circle using function.


Code: def circle_area (r):
area = 3.14 * r * r
print (area)
circle_area (2)
Output : 12.56

Q. Write a programme to print a message “Hello World” using function.


Code: def message ( ):
print (“Hello World”)
message ( )
Output : Hello World
Q. Write a programme to print volume of cuboid using function
Code : def volume_cuboid (l, b, h) :
Volume = l * b * h
print (volume)
volume_cuboid (3, 2, 4)
Output : 24

* Difference between print function and return keyword :


Print function Return Keyword
1. print is a function. 1. return is a keyword
2. It is denoted as print( ). 2. It is denoted as return
3. It will simply print the command. 3. It will not print anything. It will
return the value to the caller.
4. Print command may or may not be 4. Return command should be the last
the last statement of function body. statement of function body.
5. Example of print function for 5. Example of return keyword for
addition of two numbers : addition of two numbers :
def add (a,b) : def add (a,b) :
sum = a+b sum = a+b
print (sum) return sum
add (2,3) addition=add (2,3)
print (addition)
Output : 5
Output : 5

EXERCISE
Q.1 How does the use of functions help in programming?
Option1 Reduces the repetition of the same set of statements many times.
Option2 Makes finding error in the code easier.
Option3 Enhances the logical transparency of the program
Option4 All the above (√)

Q. 2 Functions cannot return a value


Option1 True
Option2 False (√)

You might also like