Class XII CBSE Computer Science – Practical Practice Sets
Class XII CBSE Computer Science – Practical Practice Sets
PRACTICE SET – 1
Part A – SQL
Consider the table STUDENT:
| RollNo | Name | Class | Stream | Marks | City |
|---|---|---|---|---|---|
| 101 | Amit | XII | Science | 88 | Pune |
| 102 | Riya | XII | Commerce | 76 | Mumbai |
| 103 | Karan | XII | Science | 92 | Pune |
| 104 | Neha | XII | Commerce | 81 | Delhi |
| 105 | Rahul | XII | Science | 69 | Mumbai |
Questions:
- Display all records from the table.
- Display the names and marks of students who scored more than 80.
- Display students belonging to Science stream.
- Display the names of students from Pune.
- Display students in descending order of marks.
- Find the maximum marks.
- Find the average marks.
-
Count the number of students in each stream using
GROUP BY. - Display the highest marks obtained in each stream.
-
Display students whose names start with
R.
Part B – Pandas
Create the following DataFrame:
import pandas as pd data = { 'Name':['Amit','Riya','Karan','Neha','Rahul'], 'Marks':[88,76,92,81,69], 'City':['Pune','Mumbai','Pune','Delhi','Mumbai'] } df = pd.DataFrame(data)
Perform:
- Display the DataFrame.
- Display the first 3 records.
- Display the last 2 records.
-
Display only the
NameandMarkscolumns. - Display students having marks greater than 80.
-
Add a column
Resultcontaining"Pass"for marks ≥ 40. - Sort the DataFrame according to Marks.
- Find the maximum and average marks.
Part C – Matplotlib
Using the above data:
- Draw a bar graph showing Name vs Marks.
- Add title, X-axis label and Y-axis label.
-
Display the graph using
plt.show().
PRACTICE SET – 2
Part A – SQL
Consider the table EMPLOYEE:
| EmpID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | Ravi | IT | 45000 | Pune |
| 2 | Sneha | HR | 38000 | Mumbai |
| 3 | Akash | IT | 52000 | Pune |
| 4 | Priya | Sales | 42000 | Delhi |
| 5 | Mohan | HR | 35000 | Pune |
Write SQL queries to:
- Display all employees.
- Display employees earning more than ₹40,000.
- Display employees working in IT.
- Display employees from Pune.
- Display employee names and salaries only.
- Find the minimum salary.
- Find the maximum salary.
- Find the average salary.
- Count employees department-wise.
- Find the total salary paid to employees of each department.
-
Display employees whose names end with
'a'. - Display employees in ascending order of salary.
Part B – Pandas
Create:
data = { 'Employee':['Ravi','Sneha','Akash','Priya','Mohan'], 'Department':['IT','HR','IT','Sales','HR'], 'Salary':[45000,38000,52000,42000,35000] } df = pd.DataFrame(data)
Perform:
-
Display
df.head(). -
Display
df.tail(). - Display salary column.
- Display employees earning more than 40,000.
- Calculate the mean salary.
- Calculate maximum salary.
- Sort the DataFrame by Salary.
- Group employees according to Department.
- Find department-wise average salary.
-
Add a new column
Bonusequal to 10% of Salary.
PRACTICE SET – 3
Part A – Pandas Series
Create a Series containing marks of five students:
import pandas as pd marks = pd.Series( [78, 85, 92, 67, 88], index=['Amit','Riya','Karan','Neha','Rahul'] )
Perform:
- Display the Series.
- Display the marks of Riya.
- Display marks of Amit and Karan.
- Display marks greater than 80.
- Find the maximum marks.
- Find the minimum marks.
- Find the average marks.
- Sort the Series.
- Display the index.
- Display the values.
Part B – DataFrame
Create:
data = { 'Product':['Laptop','Mobile','Tablet','Printer','Keyboard'], 'Price':[55000,25000,18000,12000,1500], 'Quantity':[5,10,7,4,20] } df = pd.DataFrame(data)
Perform:
- Display the DataFrame.
- Display information about the DataFrame.
- Display the first three rows.
- Display products having price greater than ₹15,000.
-
Add a column
Amount = Price * Quantity. - Find the total sales amount.
- Sort the DataFrame according to Price.
- Change the index of the DataFrame.
-
Delete the
Quantitycolumn. - Display the final DataFrame.
PRACTICE SET – 4
Data Handling + CSV
Create a DataFrame:
data = { 'RollNo':[1,2,3,4,5,6], 'Name':['Amit','Riya','Karan','Neha','Rahul','Sneha'], 'English':[78,88,67,91,74,83], 'Computer':[85,92,72,95,69,89], 'Economics':[76,85,70,88,73,91] } df = pd.DataFrame(data)
Questions
- Display the complete DataFrame.
- Display the first 4 records.
- Display the last 3 records.
- Calculate the average marks in Computer.
- Find the maximum marks in Economics.
- Find the minimum marks in English.
-
Add a column
Total. -
Add a column
Average. - Display students having Average ≥ 80.
- Sort students according to Average in descending order.
-
Export the DataFrame to a CSV file named
student.csv. -
Import
student.csvinto another DataFrame. - Display the imported DataFrame.
PRACTICE SET – 5
Pandas + Matplotlib
Consider the following sales data:
import pandas as pd data = { 'Month':['Jan','Feb','Mar','Apr','May','Jun'], 'Sales':[25000,32000,28000,40000,45000,38000], 'Expenses':[15000,18000,17000,22000,25000,21000] } df = pd.DataFrame(data)
Pandas Questions
- Display the DataFrame.
- Display the first three records.
- Find total sales.
- Find average sales.
- Find maximum sales.
- Find minimum expenses.
-
Add a column
Profit.
Formula:
Profit = Sales - Expenses
- Display the month having maximum sales.
- Sort the DataFrame according to Sales.
- Display months where Sales are greater than ₹30,000.
Matplotlib Questions
- Draw a line graph for Month vs Sales.
- Draw a bar graph for Month vs Sales.
- Draw a graph comparing Sales and Expenses.
- Add an appropriate title.
- Add X-axis and Y-axis labels.
- Add a legend wherever required.
PRACTICE SET – 6
SQL + Pandas + Matplotlib Integrated Practical
SQL
Consider two tables:
STUDENT
| RollNo | Name | CourseID | Marks |
|---|---|---|---|
| 1 | Amit | C01 | 85 |
| 2 | Riya | C02 | 92 |
| 3 | Karan | C01 | 76 |
| 4 | Neha | C03 | 88 |
| 5 | Rahul | C02 | 72 |
COURSE
| CourseID | CourseName |
|---|---|
| C01 | Python |
| C02 | Data Science |
| C03 | Web Development |
Write SQL queries to:
- Display all students.
- Display students scoring more than 80.
- Display students in descending order of marks.
- Find average marks.
- Find course-wise number of students.
- Find course-wise maximum marks.
-
Display student names beginning with
A. - Display student names along with their course names using a JOIN.
- Display students enrolled in Data Science.
- Display students who scored between 75 and 90.
Pandas
Create a DataFrame using the student data and:
- Display the DataFrame.
- Display students with marks > 80.
- Calculate mean marks.
- Sort by marks.
-
Add a
Resultcolumn. - Find the highest scorer.
- Export the DataFrame to CSV.
Matplotlib
Create:
- Bar graph of Student vs Marks
- Line graph of Student vs Marks
- Appropriate title and axis labels.
Comments
Post a Comment