CBSE Class 12 Computer Science: Review of Python NCERT Solutions
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
| Board | CBSE |
|---|---|
| Class | Class 12 |
| Subject | Computer Science (Python) |
| Session | 2026 |
| Language | English |
| Type | NCERT Solutions |
| Chapter | Chapter 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.
Questions and Solutions
Question 1.
- load ()
- pow () [CBSE Delhi 2016]
To invoke the specified functions, the following Python library modules need to be imported:
- For the
load()function, which is used for de-serializing Python object structures, you need to import the pickle module. - 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-inpow()function that does not require an import.)
Question 2.
- Uniform ()
- fabs () [CBSE SQP 2016]
The specified functions belong to the following Python modules:
- The
uniform()function, used to generate a random floating-point number within a specified range, belongs to the random module. - The
fabs()function, which returns the absolute value of a number as a float, belongs to the math module.
Question 3.
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)returns6round(4.1)returns4round(5.5)returns6round(4.5)returns4
math.floor(number): This function, found in themathmodule, 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)returns6math.floor(5.01)returns5math.floor(-5.1)returns-6
In summary, round() rounds to the nearest integer, while floor() always rounds down to the nearest integer.
Question 1.
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.
- sqrt()
- dump() (CBSE Outside Delhi-2016)
To use the specified functions in a Python program, you need to import the following library modules:
- For the
sqrt()function, which calculates the square root of a number, you must import the math module. - 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.
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.
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.
- Finding second occurrence of m in madam.
- get the position of an item in the list.
The required functions/methods are:
- To find the second occurrence of a character or substring within a string, you would typically use the string's
find()orindex()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. Thefind()method returns -1 if not found, whileindex()raises an error. The source impliesfind()is the answer. - 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 ofiteminmy_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?
Explanation: The `load()` function is part of the `pickle` module, which is used for serializing and de-serializing Python object structures.
Q2. The `pow()` function in Python belongs to which module?
Explanation: The `pow()` function, used for mathematical exponentiation, is available in the `math` module. Python also has a built-in `pow()` function.
Q3. Which of the following is an invalid identifier in Python?
Explanation: Identifiers in Python cannot start with a digit. '3rd_Row' starts with a digit, making it an invalid identifier.
Q4. The `fabs()` function is used for:
Explanation: The `fabs()` function from the `math` module returns the absolute value of a number, which is its distance from zero.
Q5. Which function returns the largest integer less than or equal to a given number?
Explanation: The `floor()` function returns the largest integer that is less than or equal to the input 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.