Class 11th CBSE CS
Subjective
1. Mehak, a Python programmer, wants to print the squares of all odd
numbers between 1 and 20. She wrote the following code, but it
contains errors. Correct the code and underline the corrections made.
num = 1
while num < 20
if num % 2 = 1
print(num*2)
num += 1
num = 1
while num < 20:
if num % 2 == 1:
print(num**2)
num += 1
2.Write a program in Python that takes a number as an input from the user and check whether that number is positive, negative, or zero.
# Program to check whether a number is positive, negative, or zero
num = float(input("Enter a number: "))
if num > 0:
print("The number is Positive")
elif num < 0:
print("The number is Negative")
else:
print("The number is Zero")
3.What will be the output of following statement: (9 >= 8) and (not False) or (7 < 3)
(9 >= 8) and (not False) or (7 < 3)
Step 1: Evaluate Relational Operators
9 >= 8 → True
7 < 3 → False
True and (not False) or False
Step 2: Evaluate NOT Operator
not False → True
True and True or False
Step 3: Apply Operator Precedence (not → and → or)
True and True → True
True or False → True
Final Output
True
4. What will be the output of following statement: 2**3**2 + 10 - 2
2**3**2 + 10 - 2
Step 1: Operator Precedence
Exponentiation (**) → Right to Left
Addition (+) and Subtraction (-) → Left to Right
Step 2: Evaluate Exponentiation
2**3**2
= 2**(3**2)
3**2 = 9
2**9 = 512
Step 3: Perform Addition and Subtraction
512 + 10 = 522
522 - 2 = 520
Final Output
520
5. Difference Between System Software and Application Software
| Basis of Comparison | System Software | Application Software |
|---|---|---|
| Definition | Software that manages and controls computer hardware and provides a platform for other software. | Software designed to perform specific tasks for the user. |
| Purpose | To operate and control the computer system. | To help users perform particular tasks like writing, calculating, designing, etc. |
| Dependency | Essential for the functioning of the computer. | Depends on system software to run. |
| User Interaction | Works in the background; limited direct user interaction. | Directly interacts with the user. |
| Installation | Usually pre-installed with the operating system. | Installed as per user requirement. |
| Examples | Operating Systems, Device Drivers, Utility Programs | MS Word, Excel, Photoshop, Web Browsers |
6. Output of Nested Loop Program
Given Code:
for i in range(2,5):
for j in range(1,i+1):
print(j,end="")
print()
Step 1: Values of i
range(2,5) → 2, 3, 4
Step 2: Loop Execution
When i = 2 → 12
When i = 3 → 123
When i = 4 → 1234
Final Output:
12
123
1234
7.Python Program: Check Divisibility by 3 and 5
Program Code:
# Program to check whether a number is divisible by both 3 and 5
num = int(input("Enter an integer: "))
if num % 3 == 0 and num % 5 == 0:
print("The number is divisible by both 3 and 5.")
else:
print("The number is NOT divisible by both 3 and 5.")
Explanation:
- int(input()) takes integer input from the user.
- num % 3 == 0 checks divisibility by 3.
- num % 5 == 0 checks divisibility by 5.
- The and operator ensures both conditions are true.
Example Runs:
The number is divisible by both 3 and 5.
The number is NOT divisible by both 3 and 5.
8. Python Program: Print Multiplication Table
Program Code:
# Program to print the multiplication table of a number
num = int(input("Enter an integer: "))
print(f"\nMultiplication Table of {num}:\n")
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
Explanation:
- int(input()) takes integer input from the user.
- range(1, 11) generates numbers from 1 to 10.
- The loop multiplies the number with values from 1 to 10.
- Formatted strings (f-strings) are used for clean output.
Example Output:
Multiplication Table of 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
9. Find the Binary Equivalent of (FACE)16
Step 1: Convert Each Hex Digit to 4-bit Binary
| Hex | Binary |
|---|---|
| F | 1111 |
| A | 1010 |
| C | 1100 |
| E | 1110 |
Step 2: Combine the Binary Values
F A C E
1111 1010 1100 1110
Final Answer
(FACE)16 = (1111101011001110)2
Corrected Python Program
Ravi, a student of class XI has created the following code, help him by writing the correct code in
the space given in the following coding:
Line = "Kendriya Vidyalaya Jagdalpur:1564"
Length = ____________ # code for line1
print("Total no of characters are :", Length)
cnt = 0
for j in Line:
if j._________________ : # code for line2
cnt += 1
print("Total no of digits in given Line are", ________) # code for line3
print(Line.____________) # code for line4
print("KV Code :", Line[_______]) # code for line5
Line = "Kendriya Vidyalaya Jagdalpur:1564"
Length = len(Line) # code for line1
print("Total no of characters are :", Length)
cnt = 0
for j in Line:
if j.isdigit(): # code for line2
cnt += 1
print("Total no of digits in given Line are", cnt) # code for line3
print(Line.upper()) # code for line4
print("KV Code :", Line[-4:]) # code for line5
Output:
Total no of digits in given Line are 4
KENDRIYA VIDYALAYA JAGDALPUR:1564
KV Code : 1564
Evaluation of Python Expressions
(a) 15 * (4 % 4) // 2 + 6
Step 1: 4 % 4 = 0
Expression becomes: 15 * 0 // 2 + 6
Step 2: 15 * 0 = 0
0 // 2 = 0
Step 3: 0 + 6 = 6
Final Answer: 6
(b) not 10 > 5 and 2 < 11 or not 10 < 2
Step 1:
10 > 5 → True
2 < 11 → True
10 < 2 → False
Expression becomes:
not True and True or not False
Step 2:
not True → False
not False → True
Expression becomes:
False and True or True
Step 3:
False and True → False
False or True → True
Final Answer: True
Expansion of Computer Terms
- EEPROM – Electrically Erasable Programmable Read-Only Memory
- VDU – Visual Display Unit
- LCD – Liquid Crystal Display
- OMR – Optical Mark Recognition
Module in Python and Math Module Functions
What is a Module in Python?
A module in Python is a file containing Python code (functions, variables, classes, etc.) that can be reused in other Python programs. It helps in code reusability, organization, and maintainability.
Example of Importing a Module:
import math
Two Functions of Math Module
1. math.sqrt(x)
Returns the square root of a number.
import math
print(math.sqrt(25))
Output: 5.0
2. math.factorial(x)
Returns the factorial of a non-negative integer.
import math
print(math.factorial(5))
Output: 120
Differences Between List and Tuple
| Basis | List | Tuple |
|---|---|---|
| Mutability | Lists are mutable (elements can be changed). | Tuples are immutable (elements cannot be changed). |
| Syntax | Created using square brackets [ ] | Created using parentheses ( ) |
Example:
# List
my_list = [10, 20, 30]
my_list[0] = 100 # Allowed
# Tuple
my_tuple = (10, 20, 30)
my_tuple[0] = 100 # Error (Not Allowed)
Differences Between Virus and Worm
| Basis | Virus | Worm |
|---|---|---|
| Dependency | A virus requires a host file or program to attach itself and spread. | A worm is a standalone program and does not require a host file. |
| Mode of Spread | Spreads when the infected file or program is executed by the user. | Spreads automatically through networks without user action. |
Summary
Virus → Needs a host file and user action to spread.
Worm → Self-contained and spreads automatically through networks.
Tokens in Python
What are Tokens?
Tokens are the smallest individual units of a Python program. The Python interpreter breaks the source code into tokens for analysis and execution. They are the basic building blocks of Python syntax.
Types of Python Tokens
1. Keywords
Reserved words with predefined meaning.
if, else, while, for, True, False, None, def, class, return
2. Identifiers
Names given to variables, functions, classes, etc.
name = "Ravi"
3. Literals
Fixed values in a program.
- Numeric: 10, 3.14
- String: "Hello"
- Boolean: True, False
- None: None
4. Operators
- Arithmetic: +, -, *, /, %
- Relational: >, <, ==
- Logical: and, or, not
- Assignment: =, +=
5. Punctuators (Separators)
( ), [ ], { }, , , : , ; , .
Corrected Python Code (Corrections Underlined)
Observe the following Python code very carefully and rewrite it after removing all errors with each correction underlined. Str = 'Jagdalpur' L = length(Str) For j in range(L) Print(j)
Str = 'Jagdalpur'
L = len(Str) # length() corrected to len()
for j in range(L): # For → for and colon added
print(j) # Print → print
Corrections Made:
- length(Str) → len(Str)
- For → for (Python is case-sensitive)
- Added missing colon (:) after for loop
- Print → print (Python is case-sensitive)
- Proper indentation added
List, Tuple and Dictionary in Python
1. Explain List in Python
A list is a built-in data structure in Python used to store multiple values in a single variable. It is written inside square brackets []. Lists are ordered and mutable, meaning their elements can be modified after creation.
numbers = [10, 20, 30, 40] numbers.append(50)
Lists are widely used to store and manage related data items.
2. Explain Tuple in Python
A tuple is a collection data type written inside round brackets (). Like lists, tuples are ordered collections but they are immutable, meaning their values cannot be changed after creation.
data = (1, 2, 3)
Tuples are used when data should remain constant throughout the program.
3. Explain Dictionary in Python
A dictionary stores data in key–value pairs inside curly brackets {}. Each key is unique and used to access its corresponding value. Dictionaries are mutable.
student = {"name": "Riya", "roll": 12}
Dictionaries are useful for storing structured information.
4. Differentiate between List and Tuple
A list is mutable and written using square brackets. A tuple is immutable and written using round brackets. Lists are used when data changes frequently, while tuples are used for fixed data.
5. How are elements accessed in List and Tuple?
Elements are accessed using index numbers starting from 0. Negative indexing is also allowed.
fruits = ["Apple", "Mango", "Banana"] print(fruits[0])
6. How are elements accessed in Dictionary?
Dictionary elements are accessed using keys instead of index numbers.
student = {"name": "Riya", "roll": 12}
print(student["name"])
7. Explain mutability in List and Dictionary
Lists and dictionaries are mutable, meaning their elements can be changed after creation.
numbers = [1, 2, 3]
numbers[1] = 5
student = {"name": "Riya"}
student["roll"] = 12
8. Explain immutability of Tuple
Tuples are immutable. Once created, their elements cannot be changed, added, or removed. Attempting to modify a tuple results in an error.
data = (10, 20, 30)
9. Explain slicing in List and Tuple
Slicing extracts a range of elements using the colon (:) operator.
nums = [10, 20, 30, 40, 50] print(nums[1:4])
10. Main Characteristics of Dictionary
- Stores data in key–value pairs
- Keys must be unique
- It is mutable
- Does not use index numbers
- Keys must be immutable data types
- Values can be of any data type
Dictionaries are commonly used for structured data storage.
Definitions of Computer Terms
i. Application Software
Application software refers to programs designed to perform specific tasks for users. These tasks may include word processing, calculations, designing, browsing, etc. Examples include MS Word, Excel, web browsers, and media players.
ii. Cache Memory
Cache memory is a small, high-speed memory located inside or close to the CPU. It temporarily stores frequently used data and instructions to speed up processing and reduce access time to main memory (RAM).
iii. Language Processor
A language processor is system software that translates a program written in high-level or assembly language into machine language so that the computer can execute it.
Types of Language Processors:
- Compiler
- Interpreter
- Assembler
What is Social Media? Give examples of some social media platforms with their usage.
What is Social Media?
Social Media refers to online platforms and applications that allow people to create, share, and exchange information such as messages, images, and videos through the internet. It helps users communicate and interact with others across different locations.
Examples of Social Media Platforms with Their Usage
1. Facebook
- Connecting with friends and relatives
- Sharing photos and videos
- Creating groups and pages
- Promoting businesses
2. Instagram
- Sharing pictures and short videos
- Posting stories and reels
- Following celebrities and influencers
- Advertising products
3. WhatsApp
- Sending text messages
- Sharing documents and media files
- Making voice and video calls
- Creating group chats
4. YouTube
- Watching educational and entertainment videos
- Uploading and sharing videos
- Learning through tutorials
5. LinkedIn
- Professional networking
- Searching for jobs
- Sharing career-related information
Conclusion
Social media has become an important part of modern life. It helps people stay connected, share knowledge, promote businesses, and access information easily. It should always be used responsibly.
Identity Theft Prevention and Social Media
Three Methods to Prevent Identity Theft
1. Use Strong and Unique Passwords
Create passwords that are difficult to guess. A strong password should contain uppercase and lowercase letters, numbers, and special symbols. Use different passwords for different accounts.
Example: Use Riya@2026# instead of 123456.
2. Enable Two-Factor Authentication (2FA)
Two-factor authentication provides extra security. Even if someone knows your password, they cannot log in without a verification code sent to your phone or email.
Example: Receiving an OTP while logging into your email account.
3. Do Not Share Personal Information Online
Avoid sharing sensitive information such as bank details, passwords, OTPs, or ID numbers on social media or unknown websites.
Example: Never share your ATM PIN or OTP with anyone.
Python Program to Reverse the Digits of a Number
Program Code:
num = int(input("Enter a number: "))
reverse = 0
while num > 0:
digit = num % 10 # Extract last digit
reverse = reverse * 10 + digit
num = num // 10 # Remove last digit
print("Reversed number is:", reverse)
Python Program to Find the Largest of Three Numbers
Program Code:
# Program to find the largest of three numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if num1 >= num2 and num1 >= num3:
print("The largest number is:", num1)
elif num2 >= num1 and num2 >= num3:
print("The largest number is:", num2)
else:
print("The largest number is:", num3)
Operators in Python
Definition of Operators
Operators in Python are special symbols used to perform operations on variables and values. They are used to perform calculations, comparisons, and logical decisions in a program.
Example: 5 + 3 → (+) is an operator.
Relational Operators
Relational operators are used to compare two values. The result is either True or False.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| == | Equal to | 5 == 5 | True |
| != | Not equal to | 5 != 3 | True |
| > | Greater than | 7 > 4 | True |
| < | Less than | 2 < 1 | False |
| >= | Greater than or equal to | 6 >= 6 | True |
| <= | Less than or equal to | 3 <= 5 | True |
Example Program:
a = 10
b = 20
print(a > b)
print(a != b)
Logical Operators
Logical operators are used to combine two or more conditions.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| and | True if both conditions are True | (5 > 2 and 6 > 3) | True |
| or | True if at least one condition is True | (5 > 10 or 6 > 3) | True |
| not | Reverses the result | not(5 > 2) | False |
Example Program:
x = 15
y = 10
print(x > 5 and y > 5)
print(x < 5 or y > 5)
print(not(x > 5))
Characteristics of Dictionary in Python
Introduction
A dictionary in Python is a built-in data type used to store data in the form of key–value pairs. Each key is linked to a specific value, which helps in quick and easy access of data.
Main Characteristics
1. Stores Data in Key–Value Form
Each item in a dictionary consists of a key and its corresponding value.
student = {"name": "Riya", "roll": 12}
2. Keys Must Be Unique
No two keys can be the same. If repeated, the latest value replaces the old one.
data = {"a": 10, "a": 20}
print(data)
3. Mutable in Nature
A dictionary can be modified after creation. We can add, update, or delete items.
student["marks"] = 85
4. Unordered Collection
Items are not stored in a fixed sequence. Values are accessed using keys instead of index numbers.
5. Keys Can Be Different Data Types
Keys can be integers, strings, or tuples, but they must be immutable.
info = {1: "One", "city": "Surat"}
6. Values Can Be Any Data Type
Values in a dictionary can be numbers, strings, lists, or even another dictionary.
Python Program to Swap Two Numbers Without Using a Third Variable
Method 1: Using Arithmetic Operators
# Program to swap two numbers without using a third variable
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Before swapping:")
print("num1 =", num1)
print("num2 =", num2)
num1 = num1 + num2
num2 = num1 - num2
num1 = num1 - num2
print("After swapping:")
print("num1 =", num1)
print("num2 =", num2)
Method 2: Using Multiple Assignment
# Program to swap two numbers without using a third variable
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Before swapping:")
print("num1 =", num1)
print("num2 =", num2)
num1, num2 = num2, num1
print("After swapping:")
print("num1 =", num1)
print("num2 =", num2)
Explanation
- The program accepts two numbers from the user.
- It swaps the values without using any extra variable.
- The first method uses arithmetic operations.
- The second method uses Python’s multiple assignment feature.
10 Questions with Answers on List in Python
1. What is a list in Python?
A list is a data type used to store multiple values in a single variable. The elements are written inside square brackets and separated by commas.
numbers = [10, 20, 30, 40]
2. How is a list different from a tuple?
A list is mutable, meaning its elements can be changed. A tuple is immutable, meaning its elements cannot be changed.
3. How do you access elements of a list?
Elements are accessed using index numbers starting from 0.
fruits = ["Apple", "Mango", "Banana"]
print(fruits[1])
4. What is negative indexing?
Negative indexing is used to access elements from the end of the list. -1 represents the last element.
print(fruits[-1])
5. How can you add elements to a list?
Elements can be added using append() or insert() methods.
numbers = [1, 2, 3]
numbers.append(4)
6. How can you remove elements from a list?
Elements can be removed using remove(), pop(), or del.
numbers.remove(2)
7. What is slicing in a list?
Slicing is used to access a range of elements using the colon operator.
nums = [10, 20, 30, 40, 50]
print(nums[1:4])
8. Can a list store different data types?
Yes, a list can store values of different data types.
data = [10, "Hello", 3.5]
9. How do you find the length of a list?
The len() function is used to find the number of elements.
numbers = [1, 2, 3, 4]
print(len(numbers))
10. How do you iterate through a list?
A for loop is used to traverse the elements of a list.
numbers = [1, 2, 3]
for n in numbers:
print(n)


