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

Gr_8_Coding_notes_Ln_3

The document provides an overview of functions in programming, defining a function as a reusable block of code. It outlines two types of functions (predefined and user-defined) and lists three advantages of using functions, such as reducing code duplication and improving organization. Additionally, it includes basic syntax for defining functions in Python and provides sample programs demonstrating function usage.

Uploaded by

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

Gr_8_Coding_notes_Ln_3

The document provides an overview of functions in programming, defining a function as a reusable block of code. It outlines two types of functions (predefined and user-defined) and lists three advantages of using functions, such as reducing code duplication and improving organization. Additionally, it includes basic syntax for defining functions in Python and provides sample programs demonstrating function usage.

Uploaded by

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

LEADERS PRIVATE SCHOOL, SHARJAH

CODING NOTES - GRADE 8


Ln 3 – Functions in depth

I. Answer the following


1. What is a function?
Ans. A function is a block of code that performs a task. It can be called and reused
multiple times.

2. Name the 2 types of functions in any programming language.


Ans. a) Predefined function b) User defined function

3. Give any 3 advantages of functions.


Ans: a) It reduces duplication of the code.
b) It makes the code organized and easy to understand.
c) It breaks big programs into smaller ones.

4. What is meant by calling of a function? How do we call a function?


Ans: Calling a function means running a function. If we call a function, the statements
inside the function body are executed. To call a function, we specify the function name
with the round brackets. Eg:- calc() , addno()

5. Give the Basic syntax of defining a function in Python.


Ans.
def function_name( parameter list ):
body [expression]

II. Sample Programs with functions-


a) To add two numbers b) Find area of a circle
def add_numbers(a, b): def ar_cir(rad):
sum = a + b ar = 3.14*rad*rad
print(sum) print(ar)
add_numbers(12, 13) ar_cir(2)

c) Find Volume of cuboid d) Finding the square of a number with a list of


def vol(l,b,h): numbers-
a=l*b*h def square():
print(a) a=[5,1,100]
vol(3,4,2) for i in a:
sq=i*i
print(sq)
square()

You might also like