Class 12 Informatics Practices — Important Questions
1-Mark Questions
1. What is a DataFrame in Pandas? Answer: A two-dimensional labelled data structure with rows and columns, like a spreadsheet. 2. Which Pandas method shows the first 5 rows of a DataFrame? Answer: df.head() 3. What does df.shape return? Answer: A tuple (rows, columns) giving the dimensions of the DataFrame. 4. Name the command to import Pandas. Answer: import pandas as pd 5. What is the full form of DDL? Answer: Data Definition Language. 6. Which SQL command removes a table completely including its structure? Answer: DROP TABLE 7. What does TRUNCATE do in SQL? Answer: Removes all rows from a table but keeps the table structure. 8. What is a Primary Key? Answer: A column (or set of columns) that uniquely identifies each row in a table — must be not null and unique. 9. Which SQL function counts the number of rows? Answer: COUNT(*) 10. What is LAN? Answer: Local Area Network — a network covering a small area like a building or campus. 11. Name one difference between a hub and a switch. Answer: A hub broadcasts data to all connected devices; a switch sends data only to the specific destination device. 12. What is phishing? Answer: A cyberattack that uses fake emails or websites to trick users into revealing passwords or personal information. 13. What does DNS stand for? Answer: Domain Name System — translates domain names to IP addresses. 14. What is the groupby() function used for in Pandas? Answer: To group rows by one or more columns and apply aggregate functions (sum, mean, etc.) to each group. 15. Which Matplotlib function creates a pie chart? Answer: plt.pie() 16. What is ransomware? Answer: Malware that encrypts the victim's files and demands payment to restore access. 17. What is a Foreign Key? Answer: A column in a table that refers to the Primary Key of another table, establishing a link between them. 18. Which SQL clause filters groups after GROUP BY? Answer: HAVING 19. What does df.isnull().sum() return? Answer: The count of missing (NaN) values in each column of the DataFrame. 20. What is the IT Act 2000? Answer: India's first cyber law that defines offences like hacking, data theft, and provides penalties for cybercrime.
2-Mark Questions
1. Distinguish between DELETE and TRUNCATE in SQL.
DELETE: Removes specific rows using a WHERE condition. Can be rolled back. Slower — logs each row deletion.TRUNCATE: Removes all rows at once. Cannot be rolled back. Faster — does not log individual rows.
2. What is the difference between df.iloc[] and df.loc[]?
df.iloc[]: Position-based indexing — uses integer index.df.iloc[0]= first row.df.loc[]: Label-based indexing — uses row label and column name.df.loc[0, 'Name']= value at row 0, column 'Name'.
3. List any two types of network topology with one advantage each.
- Star topology: All devices connect to a central switch. Advantage: Easy to add devices; failure of one device doesn't affect others.
- Bus topology: All devices share a single cable. Advantage: Simple and cheap for small networks.
4. What is the difference between a virus and a worm?
- Virus: Attaches itself to an existing program; spreads when the infected program is run; requires human action.
- Worm: Self-replicating program; spreads automatically across networks without any human action.
5. Write the syntax for INNER JOIN in SQL.
SELECT column_names
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
Returns only rows where there is a match in both tables.
3-Mark Questions
1. Write Python code to create a DataFrame and display rows where marks are greater than 80.
import pandas as pd
data = {
'Name': ['Anitha', 'Bala', 'Chitra', 'Devi'],
'Marks': [85, 75, 92, 68]
}
df = pd.DataFrame(data)
filtered = df[df['Marks'] > 80]
print(filtered)
2. Write SQL statements to (a) create a table, (b) insert a record, and (c) select all records.
-- (a) Create
CREATE TABLE Student (
RollNo INT PRIMARY KEY,
Name VARCHAR(50),
Marks INT
);
-- (b) Insert
INSERT INTO Student VALUES (101, 'Anitha', 85);
-- (c) Select
SELECT * FROM Student;
3. Explain three cybersecurity best practices.
4. Compare LAN, MAN, and WAN.
| Feature | LAN | MAN | WAN |
|---|---|---|---|
| Full Form | Local Area Network | Metropolitan Area Network | Wide Area Network |
| Coverage | Building / campus | City | Country / global |
| Speed | Very high | High | Moderate |
| Example | Office network | City cable TV network | Internet |
5. Write Python code to draw a bar chart showing subject-wise marks.
import matplotlib.pyplot as plt
subjects = ['Tamil', 'English', 'Maths', 'Science', 'Social']
marks = [82, 78, 95, 88, 80]
plt.bar(subjects, marks, color='steelblue')
plt.title("Subject-wise Marks")
plt.xlabel("Subject")
plt.ylabel("Marks")
plt.show()
5-Mark Questions
1. Explain the DDL commands in SQL with syntax and example.
Answer outline: DDL (Data Definition Language) commands define or modify database structure.
| Command | Purpose | Example |
|---|---|---|
CREATE | Create a new table | CREATE TABLE Student (...) |
ALTER | Modify existing table | ALTER TABLE Student ADD Grade CHAR(2) |
DROP | Delete table completely | DROP TABLE Student |
TRUNCATE | Remove all rows, keep structure | TRUNCATE TABLE Student |
RENAME | Rename a table | RENAME TABLE Student TO Learner |
Example:
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
Name VARCHAR(100),
Salary DECIMAL(10,2),
Dept VARCHAR(50)
);
ALTER TABLE Employee ADD JoinDate DATE;
2. Write a Python program using Pandas to read student data, group by city, and find average marks.
import pandas as pd
data = {
'Name': ['Anitha', 'Bala', 'Chitra', 'Devi', 'Elan'],
'Marks': [85, 72, 91, 68, 88],
'City': ['Chennai', 'Madurai', 'Chennai', 'Coimbatore', 'Madurai']
}
df = pd.DataFrame(data)
print("Full DataFrame:")
print(df)
# Group by city and find mean marks
city_avg = df.groupby('City')['Marks'].mean()
print("\nAverage marks by city:")
print(city_avg)
# Find city with highest average
print("\nCity with highest average:", city_avg.idxmax())
3. Explain the types of cyber threats with examples.
Answer outline:
| Threat | Description | Example |
|---|---|---|
| Malware | Harmful software | Virus, worm, trojan, spyware |
| Phishing | Fake emails/sites | Fake bank login page |
| Ransomware | Encrypts files, demands money | WannaCry (2017) |
| DoS/DDoS | Floods server with requests | Overwhelms website servers |
| SQL Injection | Malicious SQL in input | ' OR 1=1 -- in login form |
| Man-in-the-Middle | Intercepts communication | Public Wi-Fi snooping |
| Keylogger | Records keystrokes | Steals typed passwords |
Prevention: Antivirus software, firewall, strong passwords, regular updates, HTTPS only, VPN on public networks, 2FA.
4. What is Pandas Series? Write a Python program to create a Series and perform operations on it.
A Pandas Series is a one-dimensional labelled array capable of holding any data type. It is like a column in a spreadsheet.
import pandas as pd
# Create a Series
marks = pd.Series([85, 78, 92, 68, 95],
index=['Tamil', 'English', 'Maths', 'Social', 'Science'])
print("Series:")
print(marks)
print("\nHighest mark:", marks.max())
print("Lowest mark:", marks.min())
print("Average:", marks.mean())
print("Subjects with marks > 80:")
print(marks[marks > 80])
print("Maths marks:", marks['Maths'])
5. Explain the aggregate functions in SQL with examples. Assume a table Sales(SaleID, Product, Amount, Region).
Aggregate functions perform calculations on a set of rows and return a single value.
-- Count total sales
SELECT COUNT(*) FROM Sales;
-- Total revenue
SELECT SUM(Amount) FROM Sales;
-- Average sale amount
SELECT AVG(Amount) FROM Sales;
-- Highest sale
SELECT MAX(Amount) FROM Sales;
-- Lowest sale
SELECT MIN(Amount) FROM Sales;
-- Total sales per region
SELECT Region, SUM(Amount) AS Total
FROM Sales
GROUP BY Region;
-- Regions with total > 50000
SELECT Region, SUM(Amount) AS Total
FROM Sales
GROUP BY Region
HAVING SUM(Amount) > 50000;
Practical Exam Hints
- Always include
import pandas as pdandimport matplotlib.pyplot as pltat the top of programs - End every Matplotlib program with
plt.show() - SQL keywords in CAPS by convention (SELECT, FROM, WHERE)
- End SQL statements with semicolon (
;) - For merging questions: remember
how='inner',how='left',how='right',how='outer' - Common
df.fillna()usage:df['column'].fillna(df['column'].mean())to fill with mean
