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.
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.
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()