CBSE Class 11 Computer Science Chapter 10: Functions NCERT Solutions

NCERT Solutions PDF Class 11 PDF

CBSE Class 11 Computer Science Chapter 10, 'Functions', introduces students to essential programming concepts. This chapter covers how to utilize command-line arguments with `sys.argv` and evaluate string expressions using the `eval()` function, while also addressing error handling for issues like `NameError`. Furthermore, it explores a variety of mathematical functions available in Python's `math` module. Students will learn about functions such as `ceil()`, `floor()`, `fabs()`, `exp()`, `log10()`, and `sqrt()`. The chapter also includes trigonometric functions like `cos()`, `sin()`, `tan()`, and functions for angle conversion, namely `degrees()` and `radians()`. These solutions aim to provide a clear understanding of function usage and their practical applications, aiding students in their exam preparation.

Quick info

BoardCBSE
ClassClass 11
SubjectComputer Science
Session2026
LanguageEnglish
TypeNCERT Solutions
Chapter10. Functions

Chapter summary

Chapter 10 on Functions for CBSE Class 11 Computer Science covers the practical usage of Python's built-in functions and modules. It explains command-line arguments, string evaluation, and common mathematical and trigonometric functions. The solutions clarify the purpose and output of functions like `sys.argv`, `eval()`, `ceil()`, `floor()`, `fabs()`, `exp()`, `log10()`, `sqrt()`, `cos()`, `sin()`, `tan()`, `degrees()`, and `radians()`, along with error types like `NameError`. This chapter focuses on applying these functions to solve programming problems.

Learning outcomes

  • Understand the purpose and usage of `sys.argv` for command-line arguments.
  • Explain the functionality of the `eval()` function for string expression evaluation.
  • Identify and describe various mathematical functions like `ceil()`, `floor()`, `fabs()`, `exp()`, `log10()`, and `sqrt()`.
  • Apply trigonometric functions (`cos()`, `sin()`, `tan()`) in Python.
  • Convert angles between radians and degrees using `degrees()` and `radians()`.
  • Recognize the `NameError` exception and its common causes.

Topics covered

Paper topics

  • sys.argv
  • Command-line arguments
  • eval() function
  • String evaluation
  • NameError exception
  • math module
  • ceil()
  • floor()
  • fabs()
  • exp()
  • log10()
  • sqrt()
  • Trigonometric functions (cos, sin, tan)
  • Angle conversion (degrees, radians)

Important topics

  • sys.argv and command-line arguments
  • eval() function usage and implications
  • Core math functions (ceil, floor, fabs, sqrt, exp, log10)
  • Trigonometric and angle conversion functions

PDF preview

Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.

Loading document …
Page of
Loading page …

Questions and Solutions

Question 1

What is sys.argv?
Solution: `sys.argv` is a list in Python that contains the command-line arguments passed to a script. The first element of this list, `sys.argv[0]`, is always the name of the script itself. The subsequent elements, `sys.argv[1]`, `sys.argv[2]`, and so on, represent the arguments provided by the user when running the script from the command line.

Question 2

What can you do with the eval function?
Solution: The `eval()` function in Python evaluates a string as a Python expression. It takes a string `s` as an argument, interprets the string as code, executes it, and returns the resulting object or value. For example, `eval("5 + 3")` would return `8`.

Question 3

What does sys.argv[1:] mean?
Solution: `sys.argv[1:]` represents a slice of the `sys.argv` list. It specifically refers to all the command-line arguments passed to the script *except* for the script's name itself (which is at index 0). This slice effectively gives you a list containing only the actual arguments provided by the user.

Question 4

What type of errors does the exception type NameError correspond to?
Solution: The `NameError` exception in Python is typically raised when you try to use a variable or a function name that has not been defined or initialized in the current scope. This often occurs due to a misspelling of a variable or function name, or if you attempt to use a variable before assigning any value to it.

Question 5

Why we use ceil(x) function?
Solution: The `ceil(x)` function, usually found in the `math` module, is used to find the ceiling of a number `x`. It returns the smallest integer value that is greater than or equal to `x`. The result is returned as a float. For instance, `math.ceil(4.2)` returns `5.0`, and `math.ceil(4.0)` also returns `4.0`.

Question 6

Why we use floor(x) function?
Solution: The `floor(x)` function, typically from the `math` module, is used to find the floor of a number `x`. It returns the largest integer value that is less than or equal to `x`. The result is returned as a float. For example, `math.floor(4.8)` returns `4.0`, and `math.floor(4.0)` returns `4.0`.

Question 7

Explain fabs(x) in python?
Solution: The `fabs(x)` function, available in Python's `math` module, returns the absolute value of a number `x`. The absolute value is the non-negative value of the number, regardless of its sign. For example, `math.fabs(-5.5)` returns `5.5`, and `math.fabs(5.5)` returns `5.5`.

Question 8

What value will be return by exp(x)?
Solution: The `exp(x)` function, part of the `math` module, returns the value of 'e' raised to the power of `x` (e**x). Here, 'e' is Euler's number, the base of the natural logarithm, approximately equal to 2.71828. For example, `math.exp(1)` returns approximately `2.71828`.

Question 9

What value will be return by log10(x)?
Solution: The `log10(x)` function from the `math` module returns the base-10 logarithm of a number `x`. This function is generally more accurate for calculating base-10 logarithms than using `math.log(x, 10)`. For instance, `math.log10(100)` returns `2.0`.

Question 10

What value will be return by sqrt(x)?
Solution: The `sqrt(x)` function, found in Python's `math` module, returns the square root of a non-negative number `x`. For example, `math.sqrt(16)` returns `4.0`, and `math.sqrt(2)` returns approximately `1.41421`.

Question 11

What value will be return by cos(x)?
Solution: The `cos(x)` function, part of the `math` module, returns the cosine of an angle `x`. It's important to note that the angle `x` must be provided in radians. For example, `math.cos(0)` returns `1.0`.

Question 12

Write the output of sin(O)?
Solution: The `sin(0)` function, when called with an angle of 0 (assuming 0 radians), returns `0.0`. The sine function calculates the ratio of the opposite side to the hypotenuse in a right-angled triangle, and for an angle of 0 degrees or 0 radians, this value is zero.

Question 13

Define tan(x) function in python.
Solution: The `tan(x)` function in Python's `math` module calculates the tangent of an angle `x`. Similar to other trigonometric functions, the angle `x` must be expressed in radians. The tangent is the ratio of the sine to the cosine of the angle. For example, `math.tan(0)` returns `0.0`.

Question 14

Why we use degrees(x)?
Solution: The `degrees(x)` function is used to convert an angle `x` from radians to degrees. Many mathematical calculations and trigonometric functions in programming libraries expect angles in radians. This function provides a convenient way to convert these radian values into the more commonly understood degree measurements. The conversion formula is: degrees = radians * (180 / pi).

Question 15

What is the advantage of radians(x)?
Solution: The `radians(x)` function converts an angle `x` from degrees to radians. This is advantageous because many mathematical and scientific functions, particularly in programming libraries like Python's `math` module, are designed to work with angles measured in radians. Using this function ensures that your angle inputs are in the correct format for these functions. The conversion formula is: radians = degrees * (pi / 180).

Common mistakes

  • Confusing the purpose of `sys.argv` and `sys.argv[1:]`.
  • Misunderstanding the return values of `ceil()` and `floor()` functions.
  • Incorrectly applying trigonometric functions without considering radian input.
  • Assuming `eval()` can safely execute any arbitrary string without security risks.

Revision tips

  • Practice using `sys.argv` by running Python scripts with different command-line arguments.
  • Experiment with the `math` module functions in an interactive Python session to observe their outputs.
  • Review the definitions of ceiling and floor values to avoid confusion.
  • Understand the difference between degree and radian measures for angles and their conversion.

Practice MCQs

Q1. What does `sys.argv` represent in Python?

Q2. Which function evaluates a string as a Python expression?

Q3. What is the primary use of the `ceil(x)` function?

Q4. The `NameError` exception typically occurs when:

Q5. Which function returns the base-10 logarithm of a number?

Q6. To convert an angle from radians to degrees, which function is used?

Frequently asked questions

What is `sys.argv` used for in Python?

`sys.argv` is a list that holds the command-line arguments passed to a Python script. The first element (`sys.argv[0]`) is the script's name, and subsequent elements are the arguments provided.

How does the `eval()` function work?

The `eval()` function takes a string as input, interprets it as a Python expression, executes it, and returns the result. It's powerful but should be used cautiously due to security risks with untrusted input.

What is the difference between `ceil(x)` and `floor(x)`?

`ceil(x)` returns the smallest integer greater than or equal to x (rounds up), while `floor(x)` returns the largest integer less than or equal to x (rounds down).

When does a `NameError` occur in Python?

A `NameError` occurs when you try to use a variable or function name that has not been defined or assigned a value in the current scope. This often happens due to typos or forgetting to initialize a variable.

What are the `math` module functions covered in this chapter?

This chapter covers several `math` module functions including `ceil()`, `floor()`, `fabs()` (absolute value), `exp()` (e^x), `log10()` (base-10 logarithm), `sqrt()` (square root), trigonometric functions (`cos()`, `sin()`, `tan()`), and angle conversion functions (`degrees()`, `radians()`).

How can I use the trigonometric functions like `cos(x)`?

The trigonometric functions in Python's `math` module, such as `cos(x)`, expect the angle `x` to be in radians. You can use `math.degrees()` to convert from degrees to radians if needed.

Content reviewed by the NCERT Help team. Editorial Team and update policy

NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.