CBSE Class 12 Informatics Practices — NCERT Exercise Solutions
Unit 1 — Python for Data Handling
Key Concepts — Pandas
| Term | Description |
|---|---|
| Series | 1-D labelled array in Pandas |
| DataFrame | 2-D tabular data structure with rows and columns |
read_csv() | Read CSV file into DataFrame |
head(n) | First n rows (default 5) |
tail(n) | Last n rows |
info() | Summary of DataFrame (dtypes, null counts) |
describe() | Statistical summary (mean, std, min, max, quartiles) |
groupby() | Group data by column for aggregate operations |
loc[] | Label-based indexing |
iloc[] | Integer-based indexing |
MCQs
1. Which Pandas function is used to read a CSV file? (a) open() (b) read_csv() (c) import_csv() (d) load_csv()
2. What does df.shape return? (a) Number of rows only (b) Number of columns only (c) Tuple of (rows, columns) (d) Total number of elements
3. Which method removes rows with missing values? (a) dropna() (b) fillna() (c) drop() (d) remove_null()
4. To select rows where salary > 50000 in DataFrame df: (a) df[df['salary'] > 50000] (b) df.select('salary > 50000') (c) df.filter(salary > 50000) (d) df.query > 50000
Short Answer Questions
import pandas as pd
# (a) Create DataFrame
data = {
'Name': ['Asha', 'Ram', 'Priya', 'Raj'],
'Marks': [85, 78, 92, 65],
'Grade': ['A', 'B', 'A', 'C']
}
df = pd.DataFrame(data)
# (b) First 3 rows
print(df.head(3))
# (c) Mean of Marks column
print(df['Marks'].mean())
groupby() in Pandas? Give an example.Unit 2 — Data Visualisation with Matplotlib
Key Concepts
| Chart type | Matplotlib function | Use case |
|---|---|---|
| Line plot | plt.plot() | Trends over time |
| Bar chart | plt.bar() | Category comparison |
| Horizontal bar | plt.barh() | Categories with long labels |
| Histogram | plt.hist() | Frequency distribution |
| Scatter plot | plt.scatter() | Correlation between two variables |
| Pie chart | plt.pie() | Parts of a whole (%) |
Short Answer Questions
import matplotlib.pyplot as plt
students = ['Asha', 'Ram', 'Priya', 'Raj', 'Nita']
marks = [85, 72, 90, 65, 78]
plt.bar(students, marks, color='steelblue')
plt.title('Student Marks')
plt.xlabel('Students')
plt.ylabel('Marks')
plt.ylim(0, 100)
plt.show()
Unit 3 — SQL and Databases
Key Concepts
| Term | Definition |
|---|---|
| DDL | Data Definition Language: CREATE, ALTER, DROP, TRUNCATE |
| DML | Data Manipulation Language: INSERT, UPDATE, DELETE, SELECT |
| Primary Key | Uniquely identifies each row; cannot be NULL |
| Foreign Key | References primary key of another table |
| NULL | Absence of a value (not zero, not empty string) |
| Constraint | Rule enforced on data (NOT NULL, UNIQUE, CHECK, DEFAULT) |
MCQs
1. Which SQL command removes a table's structure permanently? (a) TRUNCATE (b) DELETE (c) DROP (d) REMOVE
2. Which aggregate function returns the number of rows? (a) SUM() (b) COUNT() (c) AVG() (d) TOTAL()
3. The HAVING clause is used with: (a) WHERE (b) GROUP BY (c) ORDER BY (d) JOIN
Short Answer Questions
Student with columns: RollNo (int, PK), Name (varchar 30, not null), Marks (decimal 5,2), Grade (char 1).CREATE TABLE Student (
RollNo INT PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Marks DECIMAL(5,2),
Grade CHAR(1)
);
WHERE and HAVING with an example.Unit 4 — Computer Networks
Key Concepts
| Term | Definition |
|---|---|
| LAN | Local Area Network — limited geographic area |
| WAN | Wide Area Network — large geographic area (internet) |
| MAN | Metropolitan Area Network — city scale |
| IP address | Unique numerical address for each device on a network |
| DNS | Domain Name System — translates domain names to IP addresses |
| HTTP/HTTPS | Protocol for web communication; HTTPS is encrypted |
| FTP | File Transfer Protocol — transferring files |
| SMTP | Simple Mail Transfer Protocol — sending email |
| POP3/IMAP | Receiving email protocols |
| Router | Connects different networks; routes packets |
| Switch | Connects devices within a LAN; smarter than hub |
MCQs
1. Which device connects a LAN to the internet? (a) Hub (b) Switch (c) Router (d) Repeater
2. What does DNS stand for? (a) Data Network System (b) Domain Name System (c) Digital Network Service (d) Dynamic Node Service
3. Which protocol is used for secure web browsing? (a) HTTP (b) FTP (c) HTTPS (d) SMTP
Short Answer Questions
Unit 5 — Cybersecurity
Key Concepts
| Threat | Description |
|---|---|
| Malware | Malicious software: virus, worm, Trojan, ransomware, spyware |
| Phishing | Fraudulent email/website pretending to be legitimate to steal credentials |
| SQL Injection | Inserting malicious SQL into web forms to access/corrupt databases |
| DoS attack | Denial of Service — flooding server to make it unavailable |
| Keylogger | Software that records keystrokes to steal passwords |
| Firewall | Software/hardware that monitors and controls network traffic |
| Encryption | Converting data into coded form to prevent unauthorised access |
Short Answer Questions
Worked Examples
Example 1 — Pandas operations on student data
import pandas as pd
df = pd.read_csv('students.csv')
# Find top scorer
print(df[df['Marks'] == df['Marks'].max()])
# Average marks by class
print(df.groupby('Class')['Marks'].mean())
# Students who passed (Marks >= 35)
passed = df[df['Marks'] >= 35]
print(f"Pass percentage: {len(passed)/len(df)*100:.1f}%")
Example 2 — SQL with aggregate functions
-- Highest marks per grade
SELECT Grade, MAX(Marks) AS Highest, MIN(Marks) AS Lowest, AVG(Marks) AS Average
FROM Student
GROUP BY Grade
ORDER BY Average DESC;
-- Students above class average
SELECT Name, Marks
FROM Student
WHERE Marks > (SELECT AVG(Marks) FROM Student);
Exam Tips
- Pandas questions always ask: create DataFrame, filter, groupby, or merge.
- SQL:
GROUP BY + HAVINGis a very common question — rememberHAVINGcomes afterGROUP BY. - Networking: know which device works at which layer (hub=physical, switch=data link, router=network).
- Cybersecurity: always answer with examples — phishing example, ransomware example.
- Chart type selection: trend over time → line; categories → bar; distribution → histogram; relationship → scatter.
