CBSE Class 12 Computer Science: Review of Python NCERT Solutions
CBSE Class 12 Computer Science Chapter 1, Review of Python, introduces fundamental programming concepts. This chapter covers essential Python library modules, including 'math' for mathematical operations and 'pickle' for object serialization. Key functions like load(), dump(), pow(), uniform(), fabs(), and sqrt() are explained, demonstrating their practical applications. The solutions also clarify the rules for creating valid identifiers in Python, distinguishing between correct and incorrect variable and function names. Furthermore, functions such as round() and floor() are detailed with examples, illustrating how they handle fractional numbers differently. This comprehensive review aims to solidify students' understanding of core Python elements, preparing them effectively for their examinations.
Quick info
| Board | CBSE |
|---|---|
| Class | Class 12 |
| Subject | Computer Science |
| Session | 2026 |
| Language | English |
| Type | NCERT Solutions |
| Chapter | 1. Review of Python |
Chapter summary
This chapter's NCERT Solutions for CBSE Class 12 Computer Science offer a thorough review of Python fundamentals. It covers identifying necessary library modules for specific functions (e.g., 'math', 'pickle'), understanding the distinction between functions like round() and floor(), and recognizing valid Python identifiers for variables and functions. The exercises focus on applying these rules and knowledge to practical scenarios, ensuring a solid grasp of basic Python syntax and library usage.
Learning outcomes
- Identify Python library modules required for specific functions.
- Differentiate between round() and floor() functions with examples.
- Recognize valid and invalid identifiers for Python variables and functions.
- Understand the purpose of functions like load(), pow(), sqrt(), and dump().
- Apply Python naming conventions for variables and functions.
Topics covered
Paper topics
- Python Library Modules
- Python Functions
- load() function
- pow() function
- uniform() function
- fabs() function
- sqrt() function
- dump() function
- round() function
- floor() function
- Python Identifiers
- Variable and Function Naming Rules
Important topics
- Valid Python Identifiers
- Python Library Modules and Functions
- round() vs. floor()
- Importing Modules
- String Manipulation Functions (find)
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
Name the Python Library modules which need to be imported to invoke the following functions:
- load ()
- pow () [CBSE Delhi 2016]
To use the specified functions, you need to import the following Python library modules:
- For the
load()function, which is used for deserializing objects, you need to import thepicklemodule. - For the
pow()function, which calculates the power of a number (base raised to an exponent), you need to import themathmodule.
Question 2
Name the modules to which the following functions belong:
- Uniform ()
- fabs () [CBSE SQP 2016]
The specified functions belong to the following Python modules:
- The
uniform()function, used for generating random floating-point numbers within a specified range, belongs to therandommodule. - The
fabs()function, which returns the absolute value of a floating-point number, belongs to themathmodule.
Question 3
Differentiate between the round() and floor() functions with the help of suitable examples. [CBSE Comptt. 2016]
The round() and floor() functions in Python are used for numerical rounding, but they operate differently:
round(number): This function returns the 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)returns6.round(4.1)returns4.round(5.5)returns6.round(4.5)returns4.
floor(number): This function returns the largest integer less than or equal to the given number. It always rounds down towards negative infinity. For example:floor(6.9)returns6.floor(5.01)returns5.floor(-5.1)returns-6.
In summary, round() aims for the closest integer, while floor() consistently rounds down.
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]
Identifiers in Python must follow specific rules: they must start with a letter or an underscore, can contain alphanumeric characters and underscores, and cannot be Python keywords. They are also case-sensitive. Based on these rules, the following identifiers cannot be used for naming variables or functions:
Total * Tax: Contains an invalid character (*), which is an operator.While: This is a Python keyword (used for loops). Keywords cannot be used as identifiers.3rd Row: Starts with a number (3) and contains a space, both of which are invalid.finally: This is a Python keyword (used in exception handling).
The valid identifiers from the list are Class (though it's a keyword, it can sometimes be used if not conflicting, but generally discouraged for variables/functions), Switch (if not a reserved keyword in a specific context, but generally avoided), Column 31, and Total.
Question 2
Name the Python Library modules which need to be imported to invoke the following functions: sqrt(), dump() (CBSE Outside Delhi-2016)
To use the specified functions, you need to import the following Python library modules:
- For the
sqrt()function, which calculates the square root of a number, you need to import themathmodule. - For the
dump()function, used to serialize (save) a Python object to a file, you need to import thepicklemodule.
Question 3
Out of the following, find the identifiers, which cannot be used for naming Variable or Functions in a Python program: Cost, Price*Qty, float, switch, Address one, Delete, Number12, do
Based on Python's identifier naming rules, the following are invalid for variables or functions:
Price*Qty: Contains an invalid operator character (*).float: This is a built-in data type name and a keyword in Python, hence it cannot be used as a variable or function name.Address one: Contains a space, which is not allowed within an identifier.do: This is a reserved keyword in Python and cannot be used as an identifier.
Valid identifiers from the list include Cost, switch (though often a keyword in other languages, it's not a strict reserved keyword in Python in the same way as 'if' or 'for', but using keywords is bad practice), Delete, and Number12.
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
The following identifiers are invalid for naming variables or functions in Python due to violations of naming rules:
Days * Rent: Contains an invalid operator (*).For: This is a reserved keyword in Python used for loops.Grand Total: Contains a space, which is not permitted in identifiers.do: This is a reserved keyword in Python.2Clients: Identifiers cannot begin with a digit.My city: Contains a space.
Valid identifiers from the list are A_price and Participantl.
Question 5
Name the function / method required for [CBSE SQP 2015]
- Finding second occurrence of m in madam.
- get the position of an item in the list.
The functions/methods required for the specified tasks are:
- To find the second occurrence of a substring (like 'm' in 'madam'), you can use the string's
find()orindex()method. To find the *second* occurrence, you would first find the first occurrence and then search again starting from the position immediately after the first one. For example, to find the second 'm' in 'madam':- Find the first 'm':
'madam'.find('m')returns0. - Search again starting from index 1:
'madam'.find('m', 1)returns2.
find()(orindex()). - Find the first 'm':
- To get the position (index) of an item in a list, you use the list's
index()method. For example, if you have a listmy_list = ['a', 'b', 'c', 'b'],my_list.index('b')will return1(the index of the first occurrence of 'b').
Common mistakes
- Using keywords as identifiers.
- Including spaces or special characters (except underscore) in identifiers.
- Starting identifiers with numbers.
- Confusing the behavior of round() and floor() functions.
- Incorrectly identifying valid vs. invalid variable/function names.
Revision tips
- Memorize common Python keywords to avoid using them as identifiers.
- Practice creating valid identifiers for variables and functions.
- Work through the examples for round() and floor() to solidify understanding.
- Review the list of functions and their corresponding library modules.
- Attempt to solve the identifier-based questions without looking at the answers first.
Practice MCQs
Q1. Which Python library module needs to be imported to use the `pow()` function?
Explanation: The `pow()` function, used for mathematical exponentiation, is part of the standard `math` module in Python.
Q2. Which of the following is an invalid identifier in Python?
Explanation: Identifiers in Python cannot start with a number. '3rd Row' also contains a space, making it invalid.
Q3. The `floor()` function in Python returns:
Explanation: The `floor()` function returns the largest integer less than or equal to the given number, effectively rounding down.
Q4. Which module is typically used for functions like `uniform()`?
Explanation: The `uniform()` function, used for generating random floating-point numbers within a specified range, belongs to the `random` module.
Q5. Which of these functions is used to find the second occurrence of a substring within a string?
Explanation: The `find()` method can be used with an optional starting position argument to find subsequent occurrences of a substring.
Frequently asked questions
What are the key Python library modules covered in this chapter?
This chapter covers essential Python library modules such as 'pickle' for object serialization and 'math' for mathematical operations, along with the 'random' module for generating random numbers.
How do `round()` and `floor()` functions differ in Python?
The `round()` function rounds a number to the nearest whole number (e.g., 5.8 becomes 6, 4.1 becomes 4), while the `floor()` function always rounds down to the nearest lower whole number (e.g., 6.9 becomes 6, 5.01 becomes 5).
What are the rules for naming variables and functions in Python?
Python identifiers must start with a letter or an underscore, followed by any number of letters, numbers, or underscores. They cannot be Python keywords, and they are case-sensitive. Identifiers cannot contain spaces or special characters like '*' or '+'.
Which functions are associated with the 'pickle' module?
The 'pickle' module is primarily associated with functions like `load()` for deserializing (loading) an object from a file and `dump()` for serializing (saving) an object to a file.
Why is it important to import specific modules in Python?
It is important to import specific modules to access the functions and classes defined within them. This keeps the program organized and avoids naming conflicts, ensuring that you use the correct functions (e.g., `math.sqrt()` instead of a potentially differently defined `sqrt()` function).
Content reviewed by the NCERT Help team. Editorial Team and update policy
NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.