Humanities/Arts Exam  >  Humanities/Arts Notes  >  Computer Science for Class 11  >  NCERT Textbook: Functions

NCERT Textbook: Functions | Computer Science for Class 11 - Humanities/Arts PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


7.1 Introduct Ion Till now we have written some programs and might 
have realised that as the problem gets complex, the 
number of lines in a program increase, which makes the 
program look bulky and dif??cult to manage. Consider 
the following problem statement: 
There is a company that manufactures tents as per 
user’s requirements. The shape of the tent is cylindrical 
surmounted by a conical top.
“Once you succeed in writing 
the programs for [these] 
complicated algorithms, they 
usually run extremely fast. 
The computer doesn’t need 
to understand the algorithm, 
its task is only to run the 
programs.”
– R. Tarjan
Chapter 7
Functions
In this chapter
 » Introduction to 
Functions
 » User De??ned      
Functions
 » Scope of a Variable
 » Python Standard 
Library
Figure 7.1: Shape of a tent
The company performs the following tasks to ??x the 
selling price of each tent. 
1. Accept user requirements for the tent, such as
a) height 
b) radius 
c) slant height of the conical part
2. Calculate the area of the canvas used
3. Calculate the cost of the canvas used for making 
the tent
4. Calculate the net payable amount by the customer 
that is inclusive of the 18% tax
The company has created a computer program for 
quick and accurate calculation for the payable amount 
as shown in program 7-1.
Ch 7.indd   143 08-Apr-19   12:23:12 PM
Reprint 2025-26
Page 2


7.1 Introduct Ion Till now we have written some programs and might 
have realised that as the problem gets complex, the 
number of lines in a program increase, which makes the 
program look bulky and dif??cult to manage. Consider 
the following problem statement: 
There is a company that manufactures tents as per 
user’s requirements. The shape of the tent is cylindrical 
surmounted by a conical top.
“Once you succeed in writing 
the programs for [these] 
complicated algorithms, they 
usually run extremely fast. 
The computer doesn’t need 
to understand the algorithm, 
its task is only to run the 
programs.”
– R. Tarjan
Chapter 7
Functions
In this chapter
 » Introduction to 
Functions
 » User De??ned      
Functions
 » Scope of a Variable
 » Python Standard 
Library
Figure 7.1: Shape of a tent
The company performs the following tasks to ??x the 
selling price of each tent. 
1. Accept user requirements for the tent, such as
a) height 
b) radius 
c) slant height of the conical part
2. Calculate the area of the canvas used
3. Calculate the cost of the canvas used for making 
the tent
4. Calculate the net payable amount by the customer 
that is inclusive of the 18% tax
The company has created a computer program for 
quick and accurate calculation for the payable amount 
as shown in program 7-1.
Ch 7.indd   143 08-Apr-19   12:23:12 PM
Reprint 2025-26
Computer SCien Ce – Cla SS xi 144
Program 7-1 Program to calculate the payable amount 
for the tent.
#Program 7-1
#Program to calculate the payable amount for the tent without 
#functions
print( "Enter values for the cylindrical part of the tent in 
meters\n")
h = ??oat(input("Enter height of the cylindrical part: "))
r = ??oat(input("Enter radius: "))
l = ??oat(input("Enter the slant height of the conical part in 
meters: "))
csa_conical = 3.14*r*l         #Area of conical part
csa_cylindrical = 2*3.14*r*h   #Area of cylindrical part
# Calculate area of the canvas used for making the tent
canvas_area = csa_conical + csa_cylindrical
print("The area of the canvas is",canvas_area,"m^2")
#Calculate cost of the canvas
unit_price = ??oat(input("Enter the cost of 1 m^2 canvas: "))
total_cost= unit_price * canvas_area
print("The total cost of canvas = ",total_cost)
#Add tax to the total cost to calculate net amount payable by the 
#customer
tax = 0.18 * total_cost;
net_price = total_cost + tax
print("Net amount payable = ",net_price)
Another approach to solve the above problem is 
to divide the program into different blocks of code as 
shown in Figure 7.2. 
Figure 7.2: Calculation of the cost of the tent
Ch 7.indd   144 08-Apr-19   12:23:12 PM
Reprint 2025-26
Page 3


7.1 Introduct Ion Till now we have written some programs and might 
have realised that as the problem gets complex, the 
number of lines in a program increase, which makes the 
program look bulky and dif??cult to manage. Consider 
the following problem statement: 
There is a company that manufactures tents as per 
user’s requirements. The shape of the tent is cylindrical 
surmounted by a conical top.
“Once you succeed in writing 
the programs for [these] 
complicated algorithms, they 
usually run extremely fast. 
The computer doesn’t need 
to understand the algorithm, 
its task is only to run the 
programs.”
– R. Tarjan
Chapter 7
Functions
In this chapter
 » Introduction to 
Functions
 » User De??ned      
Functions
 » Scope of a Variable
 » Python Standard 
Library
Figure 7.1: Shape of a tent
The company performs the following tasks to ??x the 
selling price of each tent. 
1. Accept user requirements for the tent, such as
a) height 
b) radius 
c) slant height of the conical part
2. Calculate the area of the canvas used
3. Calculate the cost of the canvas used for making 
the tent
4. Calculate the net payable amount by the customer 
that is inclusive of the 18% tax
The company has created a computer program for 
quick and accurate calculation for the payable amount 
as shown in program 7-1.
Ch 7.indd   143 08-Apr-19   12:23:12 PM
Reprint 2025-26
Computer SCien Ce – Cla SS xi 144
Program 7-1 Program to calculate the payable amount 
for the tent.
#Program 7-1
#Program to calculate the payable amount for the tent without 
#functions
print( "Enter values for the cylindrical part of the tent in 
meters\n")
h = ??oat(input("Enter height of the cylindrical part: "))
r = ??oat(input("Enter radius: "))
l = ??oat(input("Enter the slant height of the conical part in 
meters: "))
csa_conical = 3.14*r*l         #Area of conical part
csa_cylindrical = 2*3.14*r*h   #Area of cylindrical part
# Calculate area of the canvas used for making the tent
canvas_area = csa_conical + csa_cylindrical
print("The area of the canvas is",canvas_area,"m^2")
#Calculate cost of the canvas
unit_price = ??oat(input("Enter the cost of 1 m^2 canvas: "))
total_cost= unit_price * canvas_area
print("The total cost of canvas = ",total_cost)
#Add tax to the total cost to calculate net amount payable by the 
#customer
tax = 0.18 * total_cost;
net_price = total_cost + tax
print("Net amount payable = ",net_price)
Another approach to solve the above problem is 
to divide the program into different blocks of code as 
shown in Figure 7.2. 
Figure 7.2: Calculation of the cost of the tent
Ch 7.indd   144 08-Apr-19   12:23:12 PM
Reprint 2025-26
FunCtionS 145
The process of dividing a computer program into 
separate independent blocks of code or separate 
sub-problems with different names and speci??c 
functionalities is known as modular programming. 
In this chapter, we will learn about the bene??ts of 
this approach.
7.2 Funct Ions 
In programming, the use of function is one of the 
means to achieve modularity and reusability. Function 
can be de??ned as a named group of instructions that 
accomplish a speci??c task when it is invoked. Once 
de??ned, a function can be called repeatedly from 
different places of the program without writing all the 
codes of that function everytime, or it can be called from 
inside another function, by simply writing the name of 
the function and passing the required parameters, if 
any (Section 7.3). The programmer can de??ne as many 
functions as desired while writing the code. The program 
7-1 is rewritten using user de??ned functions as shown 
in program 7-2.
Program 7-2 Program to calculate the payable 
amount  for the tent using user 
de??ned functions.
#Program 7-2
#Program to calculate the cost of tent
#function de??nition 
def cyl(h,r):
     area_cyl = 2*3.14*r*h    #Area of cylindrical part
     return(area_cyl)
#function de??nition
def con(l,r):
     area_con = 3.14*r*l      #Area of conical part
     return(area_con)
#function de??nition
def post_tax_price(cost):     #compute payable amount for the tent
     tax = 0.18 * cost;
     net_price = cost + tax
     return(net_price)
print("Enter values of cylindrical part of the tent in meters:")
h = ??oat(input("Height: "))
r = ??oat(input("Radius: "))
Ch 7.indd   145 08-Apr-19   12:23:12 PM
Reprint 2025-26
Page 4


7.1 Introduct Ion Till now we have written some programs and might 
have realised that as the problem gets complex, the 
number of lines in a program increase, which makes the 
program look bulky and dif??cult to manage. Consider 
the following problem statement: 
There is a company that manufactures tents as per 
user’s requirements. The shape of the tent is cylindrical 
surmounted by a conical top.
“Once you succeed in writing 
the programs for [these] 
complicated algorithms, they 
usually run extremely fast. 
The computer doesn’t need 
to understand the algorithm, 
its task is only to run the 
programs.”
– R. Tarjan
Chapter 7
Functions
In this chapter
 » Introduction to 
Functions
 » User De??ned      
Functions
 » Scope of a Variable
 » Python Standard 
Library
Figure 7.1: Shape of a tent
The company performs the following tasks to ??x the 
selling price of each tent. 
1. Accept user requirements for the tent, such as
a) height 
b) radius 
c) slant height of the conical part
2. Calculate the area of the canvas used
3. Calculate the cost of the canvas used for making 
the tent
4. Calculate the net payable amount by the customer 
that is inclusive of the 18% tax
The company has created a computer program for 
quick and accurate calculation for the payable amount 
as shown in program 7-1.
Ch 7.indd   143 08-Apr-19   12:23:12 PM
Reprint 2025-26
Computer SCien Ce – Cla SS xi 144
Program 7-1 Program to calculate the payable amount 
for the tent.
#Program 7-1
#Program to calculate the payable amount for the tent without 
#functions
print( "Enter values for the cylindrical part of the tent in 
meters\n")
h = ??oat(input("Enter height of the cylindrical part: "))
r = ??oat(input("Enter radius: "))
l = ??oat(input("Enter the slant height of the conical part in 
meters: "))
csa_conical = 3.14*r*l         #Area of conical part
csa_cylindrical = 2*3.14*r*h   #Area of cylindrical part
# Calculate area of the canvas used for making the tent
canvas_area = csa_conical + csa_cylindrical
print("The area of the canvas is",canvas_area,"m^2")
#Calculate cost of the canvas
unit_price = ??oat(input("Enter the cost of 1 m^2 canvas: "))
total_cost= unit_price * canvas_area
print("The total cost of canvas = ",total_cost)
#Add tax to the total cost to calculate net amount payable by the 
#customer
tax = 0.18 * total_cost;
net_price = total_cost + tax
print("Net amount payable = ",net_price)
Another approach to solve the above problem is 
to divide the program into different blocks of code as 
shown in Figure 7.2. 
Figure 7.2: Calculation of the cost of the tent
Ch 7.indd   144 08-Apr-19   12:23:12 PM
Reprint 2025-26
FunCtionS 145
The process of dividing a computer program into 
separate independent blocks of code or separate 
sub-problems with different names and speci??c 
functionalities is known as modular programming. 
In this chapter, we will learn about the bene??ts of 
this approach.
7.2 Funct Ions 
In programming, the use of function is one of the 
means to achieve modularity and reusability. Function 
can be de??ned as a named group of instructions that 
accomplish a speci??c task when it is invoked. Once 
de??ned, a function can be called repeatedly from 
different places of the program without writing all the 
codes of that function everytime, or it can be called from 
inside another function, by simply writing the name of 
the function and passing the required parameters, if 
any (Section 7.3). The programmer can de??ne as many 
functions as desired while writing the code. The program 
7-1 is rewritten using user de??ned functions as shown 
in program 7-2.
Program 7-2 Program to calculate the payable 
amount  for the tent using user 
de??ned functions.
#Program 7-2
#Program to calculate the cost of tent
#function de??nition 
def cyl(h,r):
     area_cyl = 2*3.14*r*h    #Area of cylindrical part
     return(area_cyl)
#function de??nition
def con(l,r):
     area_con = 3.14*r*l      #Area of conical part
     return(area_con)
#function de??nition
def post_tax_price(cost):     #compute payable amount for the tent
     tax = 0.18 * cost;
     net_price = cost + tax
     return(net_price)
print("Enter values of cylindrical part of the tent in meters:")
h = ??oat(input("Height: "))
r = ??oat(input("Radius: "))
Ch 7.indd   145 08-Apr-19   12:23:12 PM
Reprint 2025-26
Computer SCien Ce – Cla SS xi 146
csa_cyl = cyl(h,r)  #function call 
l = ??oat(input("Enter slant height of the conical area in meters: "))
csa_con = con(l,r)  #function call
#Calculate area of the canvas used for making the tent
canvas_area = csa_cyl + csa_con
print("Area of canvas = ",canvas_area," m^2")
#Calculate cost of canvas
unit_price = ??oat(input("Enter cost of 1 m^2 canvas in rupees: "))
total_cost = unit_price * canvas_area
print("Total cost of canvas before tax = ",total_cost)
print("Net amount payable (including tax) = ",post_tax_price(total_
cost))
If we compare program 7-1 and 7-2, it is evident that 
program 7-2 looks more organised and easier to read.
7.2.1 The Advantages of Function
Suppose in further the company decides to design 
another type of tent whose base is rectangular, while 
the upper part remains the same. In such a scenario, 
some part of the existing code can be reused by calling 
the function con(l,r). If the company develops other 
products or provides services, and where 18% tax rate 
is to be applied, the programmer can use the function 
post_tax_price(cost)directly.
Thus, following are the advantages of using functions 
in a program: 
• Increases readability, particularly for longer code 
as by using functions, the program is better 
organised and easy to understand.
• Reduces code length as same code is not required 
to be written at multiple places in a program. This 
also makes debugging easier.
• Increases reusability, as function can be called from 
another function or another program. Thus, we can 
reuse or build upon already de??ned functions and 
avoid repetitions of writing the same piece of code. 
• Work can be easily divided among team members 
and completed in parallel.                                                                       
7.3 u ser d e FIned Funct Ions Taking advantage of reusability feature of functions, 
there is a large number of functions already available 
Ch 7.indd   146 08-Apr-19   12:23:13 PM
Reprint 2025-26
Page 5


7.1 Introduct Ion Till now we have written some programs and might 
have realised that as the problem gets complex, the 
number of lines in a program increase, which makes the 
program look bulky and dif??cult to manage. Consider 
the following problem statement: 
There is a company that manufactures tents as per 
user’s requirements. The shape of the tent is cylindrical 
surmounted by a conical top.
“Once you succeed in writing 
the programs for [these] 
complicated algorithms, they 
usually run extremely fast. 
The computer doesn’t need 
to understand the algorithm, 
its task is only to run the 
programs.”
– R. Tarjan
Chapter 7
Functions
In this chapter
 » Introduction to 
Functions
 » User De??ned      
Functions
 » Scope of a Variable
 » Python Standard 
Library
Figure 7.1: Shape of a tent
The company performs the following tasks to ??x the 
selling price of each tent. 
1. Accept user requirements for the tent, such as
a) height 
b) radius 
c) slant height of the conical part
2. Calculate the area of the canvas used
3. Calculate the cost of the canvas used for making 
the tent
4. Calculate the net payable amount by the customer 
that is inclusive of the 18% tax
The company has created a computer program for 
quick and accurate calculation for the payable amount 
as shown in program 7-1.
Ch 7.indd   143 08-Apr-19   12:23:12 PM
Reprint 2025-26
Computer SCien Ce – Cla SS xi 144
Program 7-1 Program to calculate the payable amount 
for the tent.
#Program 7-1
#Program to calculate the payable amount for the tent without 
#functions
print( "Enter values for the cylindrical part of the tent in 
meters\n")
h = ??oat(input("Enter height of the cylindrical part: "))
r = ??oat(input("Enter radius: "))
l = ??oat(input("Enter the slant height of the conical part in 
meters: "))
csa_conical = 3.14*r*l         #Area of conical part
csa_cylindrical = 2*3.14*r*h   #Area of cylindrical part
# Calculate area of the canvas used for making the tent
canvas_area = csa_conical + csa_cylindrical
print("The area of the canvas is",canvas_area,"m^2")
#Calculate cost of the canvas
unit_price = ??oat(input("Enter the cost of 1 m^2 canvas: "))
total_cost= unit_price * canvas_area
print("The total cost of canvas = ",total_cost)
#Add tax to the total cost to calculate net amount payable by the 
#customer
tax = 0.18 * total_cost;
net_price = total_cost + tax
print("Net amount payable = ",net_price)
Another approach to solve the above problem is 
to divide the program into different blocks of code as 
shown in Figure 7.2. 
Figure 7.2: Calculation of the cost of the tent
Ch 7.indd   144 08-Apr-19   12:23:12 PM
Reprint 2025-26
FunCtionS 145
The process of dividing a computer program into 
separate independent blocks of code or separate 
sub-problems with different names and speci??c 
functionalities is known as modular programming. 
In this chapter, we will learn about the bene??ts of 
this approach.
7.2 Funct Ions 
In programming, the use of function is one of the 
means to achieve modularity and reusability. Function 
can be de??ned as a named group of instructions that 
accomplish a speci??c task when it is invoked. Once 
de??ned, a function can be called repeatedly from 
different places of the program without writing all the 
codes of that function everytime, or it can be called from 
inside another function, by simply writing the name of 
the function and passing the required parameters, if 
any (Section 7.3). The programmer can de??ne as many 
functions as desired while writing the code. The program 
7-1 is rewritten using user de??ned functions as shown 
in program 7-2.
Program 7-2 Program to calculate the payable 
amount  for the tent using user 
de??ned functions.
#Program 7-2
#Program to calculate the cost of tent
#function de??nition 
def cyl(h,r):
     area_cyl = 2*3.14*r*h    #Area of cylindrical part
     return(area_cyl)
#function de??nition
def con(l,r):
     area_con = 3.14*r*l      #Area of conical part
     return(area_con)
#function de??nition
def post_tax_price(cost):     #compute payable amount for the tent
     tax = 0.18 * cost;
     net_price = cost + tax
     return(net_price)
print("Enter values of cylindrical part of the tent in meters:")
h = ??oat(input("Height: "))
r = ??oat(input("Radius: "))
Ch 7.indd   145 08-Apr-19   12:23:12 PM
Reprint 2025-26
Computer SCien Ce – Cla SS xi 146
csa_cyl = cyl(h,r)  #function call 
l = ??oat(input("Enter slant height of the conical area in meters: "))
csa_con = con(l,r)  #function call
#Calculate area of the canvas used for making the tent
canvas_area = csa_cyl + csa_con
print("Area of canvas = ",canvas_area," m^2")
#Calculate cost of canvas
unit_price = ??oat(input("Enter cost of 1 m^2 canvas in rupees: "))
total_cost = unit_price * canvas_area
print("Total cost of canvas before tax = ",total_cost)
print("Net amount payable (including tax) = ",post_tax_price(total_
cost))
If we compare program 7-1 and 7-2, it is evident that 
program 7-2 looks more organised and easier to read.
7.2.1 The Advantages of Function
Suppose in further the company decides to design 
another type of tent whose base is rectangular, while 
the upper part remains the same. In such a scenario, 
some part of the existing code can be reused by calling 
the function con(l,r). If the company develops other 
products or provides services, and where 18% tax rate 
is to be applied, the programmer can use the function 
post_tax_price(cost)directly.
Thus, following are the advantages of using functions 
in a program: 
• Increases readability, particularly for longer code 
as by using functions, the program is better 
organised and easy to understand.
• Reduces code length as same code is not required 
to be written at multiple places in a program. This 
also makes debugging easier.
• Increases reusability, as function can be called from 
another function or another program. Thus, we can 
reuse or build upon already de??ned functions and 
avoid repetitions of writing the same piece of code. 
• Work can be easily divided among team members 
and completed in parallel.                                                                       
7.3 u ser d e FIned Funct Ions Taking advantage of reusability feature of functions, 
there is a large number of functions already available 
Ch 7.indd   146 08-Apr-19   12:23:13 PM
Reprint 2025-26
FunCtionS 147
in Python under standard library (section 7.5). We can 
directly call these functions in our program without 
de??ning them. However, in addition to the standard 
library functions, we can de??ne our own functions while 
writing the program. Such functions are called user 
de??ned functions. Thus, a function de??ned to achieve 
some task as per the programmer's requirement is 
called a user de??ned function.
7.3.1 Creating User De??ned Function
A function de??nition begins with def (short for de??ne).
The syntax for creating a user de??ned function is 
as follows:
• The items enclosed in "[ ]" are called parameters 
and they are optional. Hence, a function may or 
may not have parameters. Also, a function may or 
may not return a value.
• Function header always ends with a colon (:).
• Function name should be unique. Rules for naming 
identi??ers also applies for function naming.
• The statements outside the function indentation 
are not considered as part of the function.
Program 7-3 Write a user de??ned function to add 2   
numbers and display their sum.
#Program 7-3
#Function to add two numbers
#The requirements are listed below:
 #1. We need to accept 2 numbers from the user. 
 #2. Calculate their sum
 #3. Display the sum.
#function de??nition
def addnum():
    fnum = int(input("Enter ??rst number: "))
    snum = int(input("Enter second number: "))
    sum = fnum + snum
    print("The sum of ",fnum,"and ",snum,"is ",sum)
    
#function call
addnum()
Ch 7.indd   147 15-Jun-21   11:16:13 AM
Reprint 2025-26
Read More
33 docs|11 tests

FAQs on NCERT Textbook: Functions - Computer Science for Class 11 - Humanities/Arts

1. What are the different types of functions discussed in the NCERT textbook on Functions?
Ans. The NCERT textbook on Functions discusses several types of functions including linear functions, quadratic functions, polynomial functions, rational functions, and exponential functions. Each type has its own characteristics, such as the degree of the polynomial in polynomial functions or the constant rate of change in linear functions.
2. How do you determine the domain and range of a function?
Ans. The domain of a function consists of all possible input values (x-values) that can be used without causing any mathematical issues, such as division by zero or taking the square root of a negative number. The range includes all possible output values (y-values) that the function can produce. To determine the domain and range, one can analyze the function's equation and identify any restrictions on the input and output values.
3. What is the significance of the graphical representation of functions?
Ans. The graphical representation of functions is significant as it provides a visual understanding of how the function behaves. It helps in identifying key features such as intercepts, maximum and minimum points, and the overall shape of the function. Graphs also facilitate the comparison of different functions and the analysis of their intersection points.
4. Can you explain the concept of inverse functions as outlined in the textbook?
Ans. An inverse function essentially reverses the effects of the original function. If a function f takes an input x and produces an output y, the inverse function, denoted as f⁻¹, takes y and returns x. The textbook emphasizes that for a function to have an inverse, it must be one-to-one, meaning each output is produced by exactly one input. This can often be verified using the horizontal line test on its graph.
5. What methods are used to solve equations involving functions?
Ans. The textbook outlines several methods to solve equations involving functions, including substitution, factoring, and graphing. Substitution involves replacing variables to simplify equations, while factoring can help in finding the roots of polynomial equations. Graphing provides a visual method to identify solutions where the function intersects the x-axis. Additionally, numerical methods may also be employed for more complex functions.
Related Searches

NCERT Textbook: Functions | Computer Science for Class 11 - Humanities/Arts

,

past year papers

,

NCERT Textbook: Functions | Computer Science for Class 11 - Humanities/Arts

,

MCQs

,

shortcuts and tricks

,

Exam

,

Previous Year Questions with Solutions

,

study material

,

Sample Paper

,

mock tests for examination

,

Extra Questions

,

practice quizzes

,

Viva Questions

,

Important questions

,

Objective type Questions

,

Summary

,

pdf

,

NCERT Textbook: Functions | Computer Science for Class 11 - Humanities/Arts

,

ppt

,

Semester Notes

,

video lectures

,

Free

;