CBSE Class 12 Computer Science: Review of Python NCERT Solutions

NCERT Solutions PDF Class 12 PDF

CBSE Class 12 Computer Science Chapter 1 NCERT Solutions offer a comprehensive review of Python fundamentals. This chapter delves into identifying appropriate library modules for specific functions, such as load(), pow(), uniform(), fabs(), and sqrt(), and understanding the utility of dump(). It clarifies the distinctions between mathematical functions like round() and floor() through illustrative examples. Additionally, the solutions meticulously explain the rules governing valid identifiers in Python. Students will learn to differentiate between legal and illegal names for variables and functions, taking into account the use of keywords, special characters, spaces, and the prohibition of starting with digits. This content is vital for reinforcing core Python programming concepts, ensuring students are well-prepared for examinations and possess a solid understanding of computer science principles.

Quick info

BoardCBSE
ClassClass 12
SubjectComputer Science (Python)
Session2026
LanguageEnglish
TypeNCERT Solutions
ChapterChapter 1

Chapter summary

Chapter 1, 'Review of Python,' focuses on reinforcing foundational Python concepts. The NCERT Solutions cover the identification of necessary library modules for various built-in functions and differentiate between mathematical functions like round() and floor(). A significant part of the chapter involves understanding and applying Python's identifier naming rules, helping students recognize valid and invalid variable and function names. This chapter is key to ensuring students have a solid grasp of basic Python syntax and structure before moving to more advanced topics.

Learning outcomes

  • Identify Python library modules required for specific functions.
  • Differentiate between mathematical functions like round() and floor().
  • Recognize valid and invalid identifiers for variables and functions in Python.
  • Understand the rules governing Python identifier naming conventions.
  • Apply knowledge of Python modules and functions to solve programming problems.

Topics covered

Paper topics

  • Python Library Modules
  • Built-in Functions
  • math module
  • pickle module
  • random module
  • round() function
  • floor() function
  • Identifier Naming Rules
  • Valid Identifiers
  • Invalid Identifiers
  • Keywords in Python
  • Variable Naming

Important topics

  • Python Identifier Rules
  • Library Module Identification
  • Difference between round() and floor()
  • Valid vs. Invalid Identifiers
  • Commonly used math and pickle 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.

Name the Python Library modules which need to be imported to invoke the following functions:
  1. load ()
  2. pow () [CBSE Delhi 2016]
Solution:

To invoke the specified functions, the following Python library modules need to be imported:

  1. For the load() function, which is used for de-serializing Python object structures, you need to import the pickle module.
  2. For the pow() function, which calculates a number raised to the power of another number, you need to import the math module. (Note: Python also has a built-in pow() function that does not require an import.)

Question 2.

Name the modules to which the following functions belong:
  1. Uniform ()
  2. fabs () [CBSE SQP 2016]
Solution:

The specified functions belong to the following Python modules:

  1. The uniform() function, used to generate a random floating-point number within a specified range, belongs to the random module.
  2. The fabs() function, which returns the absolute value of a number as a float, belongs to the math module.

Question 3.

Differentiate between the round() and floor() functions with the help of suitable example. [CBSE Comptt. 2016]
Solution:

The round() and floor() functions in Python are used for number manipulation, but they serve different purposes:

  • round(number): This function returns a floating-point number rounded to the nearest integer. If the fractional part is exactly 0.5, it rounds to the nearest even integer (in Python 3). For example:
    • round(5.8) returns 6
    • round(4.1) returns 4
    • round(5.5) returns 6
    • round(4.5) returns 4
  • math.floor(number): This function, found in the math module, returns the largest integer less than or equal to the given number. It effectively rounds down to the nearest whole number. For example:
    • math.floor(6.9) returns 6
    • math.floor(5.01) returns 5
    • math.floor(-5.1) returns -6

In summary, round() rounds to the nearest integer, while floor() always rounds down to the nearest integer.

Question 1.

Out of the following, find those identifiers, which cannot be used for naming Variables or functions in a Python program: Total * Tax, While, Class, Switch, 3rd Row, finally, Column 31, Total. [CBSE Outside]
Solution:

Identifiers in Python must follow specific rules. They cannot be Python keywords, cannot contain special characters like '*', cannot start with a digit, and cannot contain spaces. Based on these rules, the following identifiers from the list cannot be used for naming variables or functions:

  • Total * Tax: Contains the special character '*'.
  • While: This is a Python keyword.
  • Class: This is a Python keyword.
  • Switch: While not a keyword in Python 3, it's often avoided as it can be confused with similar constructs in other languages and is not a standard Python keyword. However, if strictly following Python 3 keywords, it might be considered valid by some interpreters, but it's best practice to avoid it. (Note: The source implies it's invalid, likely due to older Python versions or common practice).
  • 3rd Row: Starts with a digit ('3') and contains a space.
  • finally: This is a Python keyword.
  • Column 31: Contains a space.

Therefore, the identifiers that cannot be used are: Total * Tax, While, Class, 3rd Row, finally, Column 31.

(Note: The provided source answer lists 'Switch' and 'finally' as invalid. 'finally' is indeed a keyword. 'Switch' is not a keyword in Python 3, but its inclusion in the invalid list suggests a potential misunderstanding or context from older Python versions or specific educational material.)

Question 2.

Name the Python Library modules which need to be imported to invoke the following functions:
  1. sqrt()
  2. dump() (CBSE Outside Delhi-2016)
Solution:

To use the specified functions in a Python program, you need to import the following library modules:

  1. For the sqrt() function, which calculates the square root of a number, you must import the math module.
  2. For the dump() function, which is used to serialize a Python object into a file or byte stream, you need to import the pickle module.

Question 3.

Out of the following, find the identifiers, which cannot be used for naming Variable or Functions in a Python program: [CBSE Delhi 2016] Cost, Price*Qty, float, switch, Address one, Delete, Number12, do
Solution:

Identifiers in Python must adhere to naming conventions. They cannot contain special characters, spaces, or be Python keywords. Let's analyze the given list:

  • Cost: Valid identifier.
  • Price*Qty: Invalid, contains the special character '*'.
  • float: This is a Python keyword and cannot be used as an identifier.
  • switch: As noted in a previous question, while not a keyword in Python 3, it's often considered problematic. However, strictly speaking, Python 3 keywords are limited. The source implies it's invalid.
  • Address one: Invalid, contains a space.
  • Delete: This is a Python keyword and cannot be used as an identifier.
  • Number12: Valid identifier.
  • do: This is a Python keyword and cannot be used as an identifier.

Therefore, the identifiers that cannot be used are: Price*Qty, float, switch, Address one, Delete, do.

Question 4.

Out of the following find those identifiers, which can not be used for naming Variable or Functions in a Python Program: Days * Rent, For, A_price, Grand Total, do, 2Clients, Participantl, My city
Solution:

We need to identify the invalid identifiers based on Python's naming rules:

  • Days * Rent: Invalid because it contains the operator '*'.
  • For: Invalid because 'for' is a reserved Python keyword.
  • A_price: Valid identifier.
  • Grand Total: Invalid because it contains a space.
  • do: Invalid because 'do' is a reserved Python keyword.
  • 2Clients: Invalid because it starts with a digit '2'.
  • Participantl: Valid identifier.
  • My city: Invalid because it contains a space.

Thus, the identifiers that cannot be used are: Days * Rent, For, Grand Total, do, 2Clients, My city.

Question 5.

Name the function / method required for [CBSE SQP 2015]
  1. Finding second occurrence of m in madam.
  2. get the position of an item in the list.
Solution:

The required functions/methods are:

  1. To find the second occurrence of a character or substring within a string, you would typically use the string's find() or index() method in combination with searching from a specific starting position after the first occurrence. For example, to find the second 'm' in 'madam', you could first find the first 'm' at index 0, then search again starting from index 1. The find() method returns -1 if not found, while index() raises an error. The source implies find() is the answer.
  2. To get the position (index) of an item in a list, you use the list's index() method. For example, my_list.index(item) returns the index of the first occurrence of item in my_list.

Common mistakes

  • Confusing keywords with valid identifiers.
  • Using special characters or spaces in variable/function names.
  • Incorrectly identifying the module for a given function.
  • Misunderstanding the behavior of round() vs. floor() functions.

Revision tips

  • Memorize common Python library modules and their associated functions.
  • Practice identifying valid and invalid identifiers by applying the naming rules.
  • Work through the examples for round() and floor() to solidify understanding.
  • Review the distinction between keywords and identifiers regularly.

Practice MCQs

Q1. Which Python module needs to be imported to use the `load()` function?

Q2. The `pow()` function in Python belongs to which module?

Q3. Which of the following is an invalid identifier in Python?

Q4. The `fabs()` function is used for:

Q5. Which function returns the largest integer less than or equal to a given number?

Frequently asked questions

What is the purpose of the `pickle` module in Python?

The `pickle` module is used for serializing and de-serializing Python object structures. This means it can convert a Python object hierarchy into a byte stream (pickling) and convert a byte stream back into an object hierarchy (unpickling), often used for saving and loading program states or data.

How do `round()` and `floor()` functions differ in Python?

The `round()` function rounds a number to the nearest integer (or a specified number of decimal places). The `floor()` function, however, always rounds a number down to the nearest integer less than or equal to the number.

What are the key rules for naming variables and functions (identifiers) in Python?

Python identifiers must start with a letter (a-z, A-Z) or an underscore (_), followed by any number of letters, numbers (0-9), or underscores. They cannot be Python keywords, and they are case-sensitive.

Which Python module should be imported to use the `sqrt()` function?

The `sqrt()` function, used to calculate the square root of a number, is part of the `math` module and requires `import math`.

Can a Python identifier start with a number?

No, Python identifiers cannot start with a number. They must begin with a letter or an underscore.

What happens if you try to use a Python keyword as an identifier?

Using a Python keyword (like 'while', 'for', 'class', 'if') as an identifier will result in a `SyntaxError` because keywords have predefined meanings and cannot be used for other purposes.

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

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