Skip to content
← Computer Science

Computer Science · Class 11 Optional

Ch 7Functions — Class 11 Computer Science, concept-first.

As programs grow to solve bigger problems, the number of lines of code grows with them. A long, single-block program quickly becomes bulky, hard to read and hard to maintain — spotting an error or changing one calculation means wading through the whole file.

40

Q&A

22

Concepts

Not available

Exam weightage

Start learning — read this chapter →

Key concepts

Hover a concept to preview it and jump to its most relevant Q&A.

Simple Interest Calculation

Imagine you lend a friend ₹100. A year later, they return the ₹100. You're even — but you also missed the chance to use that ₹100 yourself for a whole year. That inconvenience has a price.

Start with this concept →

Chapter contents

The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.

7.1

Introduction

As programs grow to solve bigger problems, the number of lines of code grows with them. A long, single-block program quickly becomes bulky, hard to read and hard to maintain — spotting an error or cha…

7.2

Functions

In programming, the function is one of the chief means of achieving modularity and reusability. A function can be defined as a named group of instructions that accomplishes a specific task when it is…

7.2.1

The Advantages of Function

Functions pay off the moment requirements change or grow — existing code can be reused instead of rewritten.

7.3

User Defined Functions

Because functions are reusable, Python ships with a very large number of them ready-made: the standard library (explored in Section 7.5) contains functions we can call in our programs without ever def…

7.3.1

Creating User Defined Function

A function definition always begins with the keyword def (short for define). The general syntax for creating a user defined function is:

7.3.2

Arguments and Parameters

6 Q

In the previous example, addnum() collected its numbers from the user inside the function. A user defined function can instead receive values at the moment it is called.

7.3.3

Functions Returning Value

A function may or may not send a value back when it is called. The return statement is what sends values out of a function.

7.3.4

Flow of Execution

3 Q

Flow of execution is the order in which the statements of a program are actually executed.

7.4

Scope of a Variable

2 Q

A variable defined inside a function cannot be used outside it. Every variable in a program has a well-defined region where it is accessible, and the part of the program in which a variable can be acc…

7.5

Python Standard Library

Python comes with a very extensive standard library — a large collection of ready-made functionality that can be called in a program as and when required.

7.5.1

Built-in functions

Built-in functions are the ready-made functions of Python — functions so frequently needed that they are permanently available in every program, with no import and no definition required.

7.5.2

Module

3 Q

Besides its built-in functions, the Python standard library contains a large number of modules. The distinction is one of level: a function is a grouping of instructions, while a module is a grouping…

Summary

- Functions are used in programming to achieve modularity and reusability. - A function is a named group of instructions that executes when the function is invoked (called) by its name.

Exercises

More questions

15 Q
+Show 5 questions5 questions
  1. Q1To secure your account, whether it be an email, online bank account or any other account, it is important that we use authentication. Use yo…Free
  2. Q2XYZ store plans to give festival discount to its customers. The store management has decided to give discount on the following criteria: | S…Free
  3. Q3‘Play and learn’ strategy helps toddlers understand concepts in a fun way. Being a senior student you have taken responsibility to develop a…Preview
  4. Q4Take a look at the series below: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55… To form the pattern, start by writing 1 and 1. Add them together to get 2…Preview
  5. Q5Create a menu driven program using user defined functions to implement a calculator that performs the following: a) Basic arithmetic operati…Preview
+Show 8 questions8 questions
  1. Q1Write a program to check the divisibility of a number by 7 that is passed as a parameter to the user defined function.Free
  2. Q2Write a program that uses a user defined function that accepts name and gender (as M for Male, F for Female) and prefixes Mr/Ms on the basis…Free
  3. Q3Write a program that has a user defined function to accept the coefficients of a quadratic equation in variables and calculates its determin…Free
  4. Q4ABC School has allotted unique token IDs from (1 to 600) to all the parents for facilitating a lucky draw on the day of their Annual day fun…Preview
  5. Q5Write a program that implements a user defined function that accepts Principal Amount, Rate, Time, Number of Times the interest is compounde…Preview
  6. Q6Write a program that has a user defined function to accept 2 numbers as parameters, if number 1 is less than number 2 then numbers are swapp…Preview
  7. Q7Write a program that contains user defined functions to calculate area, perimeter or surface area whichever is applicable for various shapes…Preview
  8. Q8Write a program that creates a GK quiz consisting of any five questions of your choice. The questions should be displayed randomly. Create a…Preview
+Show 2 questions2 questions
  1. Q1For the SMIS system extended in Chapter 6 let us do the following: 7.1 Convert all the functionality in Chapter 5 and 6 using user defined f…Free
  2. Q2For the SMIS system extended in Chapter 6 let us do the following: 7.2 Add another user defined function to the above menu to check if the s…Preview