CBSE Class 11 Computer Science: Chapter 10 - Functions NCERT Solutions

NCERT Solutions PDF Class 11 PDF

This chapter delves into essential Python programming concepts, focusing on functions and their applications. Students will explore command-line arguments using `sys.argv`, understand the utility of the `eval()` function for dynamic expression evaluation, and learn about various mathematical functions provided by the `math` module. Key functions covered include `ceil()`, `floor()`, `fabs()`, `exp()`, `log10()`, `sqrt()`, `cos()`, `sin()`, `tan()`, `degrees()`, and `radians()`. The solutions also touch upon handling `NameError` exceptions, which occur when a variable or function is not defined. These detailed explanations and solutions are designed to help Class 11 students grasp these fundamental programming tools, clarify doubts, and prepare effectively for their examinations by reinforcing theoretical knowledge with practical examples.

Quick info

BoardCBSE
ClassClass 11
SubjectComputer Science
Session2026
LanguageEnglish
TypeNCERT Solutions
ChapterChapter 10

Chapter summary

Chapter 10 of the CBSE Class 11 Computer Science syllabus focuses on 'Functions'. This section provides NCERT Solutions that explain command-line arguments, the `eval()` function, and a variety of mathematical functions available in Python's `math` module. It covers functions for rounding (`ceil`, `floor`), absolute value (`fabs`), exponentiation (`exp`), logarithms (`log10`), square roots (`sqrt`), trigonometric operations (`cos`, `sin`, `tan`), and angle conversions (`degrees`, `radians`). Additionally, it addresses the `NameError` exception. These solutions aim to provide clear, step-by-step understanding for students.

Learning outcomes

  • Understand the purpose and usage of `sys.argv` for command-line arguments.
  • Explain the functionality of the `eval()` function in Python.
  • Identify and describe various mathematical functions like `ceil`, `floor`, `fabs`, `exp`, `log10`, `sqrt`, `cos`, `sin`, `tan`.
  • Differentiate between `degrees()` and `radians()` for angle conversions.
  • Recognize the `NameError` exception and its common causes.
  • Apply mathematical functions to solve computational problems.

Topics covered

Paper topics

  • Command-line arguments (`sys.argv`)
  • Expression evaluation (`eval()` function)
  • Mathematical functions (`math` module)
  • Ceiling function (`math.ceil`)
  • Floor function (`math.floor`)
  • Absolute value function (`math.fabs`)
  • Exponential function (`math.exp`)
  • Logarithm function (`math.log10`)
  • Square root function (`math.sqrt`)
  • Trigonometric functions (`math.cos`, `math.sin`, `math.tan`)
  • Angle conversion functions (`math.degrees`, `math.radians`)
  • Error handling (`NameError`)

Important topics

  • Command-line arguments (`sys.argv`)
  • Expression evaluation (`eval()` function)
  • Core mathematical functions (`ceil`, `floor`, `sqrt`, `log10`)
  • Trigonometric and angle conversion functions
  • Understanding and handling `NameError`

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 holds 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, followed by any additional arguments provided when the script was executed. For example, if you run `python my_script.py arg1 arg2`, then `sys.argv` would be `['my_script.py', 'arg1', 'arg2']`.

Question 2

What can you do with the eval function?
Solution: The `eval(s)` function in Python evaluates a string `s` as a Python expression. It parses the string, executes it as code, and returns the result of the expression. For instance, `eval('5 + 3')` would return `8`. It's important to use `eval()` with caution, especially with untrusted input, as it can execute arbitrary code.

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, excluding the script name itself (`sys.argv[0]`). This slice provides a convenient way to access 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 raised when a local or global name (variable, function, or class) is not found. This typically occurs when you try to use a variable or call a function before it has been assigned a value or defined, or if there's a misspelling in the name.

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`. For example, `math.ceil(4.2)` returns `5.0`, and `math.ceil(-4.2)` 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`. For instance, `math.floor(4.7)` returns `4.0`, and `math.floor(-4.2)` returns `-5.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` as a floating-point number. The absolute value is the non-negative value of the number, regardless of its sign. For example, `math.fabs(-5.7)` returns `5.7`, and `math.fabs(5.7)` also returns `5.7`.

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 calculates and returns the base-10 logarithm of `x`. This function is generally more accurate for base-10 logarithms than using `math.log(x, 10)`. For example, `math.log10(100)` returns `2.0`.

Question 10

What value will be return by sqrt(x)?
Solution: The `sqrt(x)` function, found in the `math` module, computes and returns the square root of `x`. It requires `x` to be a non-negative number. For example, `math.sqrt(16)` returns `4.0`.

Question 11

What value will be return by cos(x)?
Solution: The `cos(x)` function, part of the `math` module, returns the cosine of the 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 (typically as `math.sin(0)`), returns `0.0`. This is because the sine of an angle of 0 radians is 0.

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. 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. This is useful when you have an angle measured in radians but need to express it in degrees, which is often more intuitive. The conversion formula is degrees = radians * (180 / pi). For example, `math.degrees(math.pi)` returns `180.0`.

Question 15

What is the advantage of radians(x)?
Solution: The `radians(x)` function converts an angle `x` from degrees to radians. Its advantage lies in enabling the use of trigonometric functions in Python's `math` module, which require angles in radians. For instance, if you have an angle in degrees, you can convert it using `math.radians()` before passing it to `math.sin()`, `math.cos()`, or `math.tan()`. For example, `math.radians(180)` returns approximately `3.14159` (pi).

Common mistakes

  • Confusing `sys.argv` with list indexing for arguments.
  • Misunderstanding the return type or behavior of `eval()`.
  • Incorrectly applying rounding functions (`ceil` vs. `floor`).
  • Not specifying the correct unit (radians/degrees) for trigonometric functions.
  • Assuming variables or functions are defined when they are not, leading to `NameError`.

Revision tips

  • Practice using `sys.argv` by running Python scripts with different command-line inputs.
  • Experiment with the `eval()` function to see how it handles various string expressions.
  • Work through examples for each `math` module function to solidify understanding of their outputs.
  • Pay close attention to the units (radians vs. degrees) when using trigonometric and conversion functions.
  • Review common error types like `NameError` and understand how to prevent them.

Practice MCQs

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

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

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

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

Q5. A `NameError` typically occurs when:

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

Frequently asked questions

What are command-line arguments in Python and how are they accessed?

Command-line arguments are values passed to a Python script when it is executed from the terminal. They are accessed using the `sys.argv` list, where `sys.argv[0]` is the script name and subsequent elements are the arguments.

How does the `eval()` function work?

The `eval(s)` function takes a string `s` containing a Python expression, evaluates that expression, and returns the resulting object. It's powerful but should be used cautiously due to security implications.

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

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

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 is not accessible in the current scope. This often happens due to typos or forgetting to initialize a variable.

How can I convert angles between radians and degrees in Python?

You can use the `math.degrees(x)` function to convert an angle `x` from radians to degrees, and `math.radians(x)` to convert an angle `x` from degrees to radians.

Are the trigonometric functions in Python's `math` module based on degrees or radians?

The trigonometric functions like `cos()`, `sin()`, and `tan()` in Python's `math` module expect the input angle `x` to be in radians.

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

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