IP Class 12 Practical Questions
IP Class 12 Practical Questions
ANSWERS
(i)
import pandas as pd
L=[{'Test1':45,'Test2':58,'Test3':47,'Test4':65},
{'Test1':36,'Test2':85,'Test3':44,'Test4':46},
{'Test1':78,'Test2':96,'Test3':88,'Test4':77},
{'Test1':54,'Test2':50,'Test3':74,'Test4':85}
]
marks=pd.DataFrame(L,index=['Ram','Peter','Alex','John'])
print(marks)
(ii)
print(marks.head(3))
(or)
print(marks[0:3])
(or)
print(marks.iloc[0:3])
(or)
print(marks.loc['Ram':'Alex'])
iii) marks['Total']=marks['Test1']+marks['Test2']+marks['Test3']+marks['Test4']
Page 1 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
Part B
2. Write program in python to create a line chart with the given data
and also set the name to . x-axis as ename, y axis as sal, title as
simple. Also save graph as simple.pdf
ename=[‘Hari’,’Riya’,’Chandhan’,’Joe’,’Mita’]
sal=[4000,6000,5000,3500,8000] 5M
answer
import matplotlib.pyplot as plt
ename=['Hari','Riya','Chandhan','Joe','Mita']
sal=[4000,6000,5000,3500,8000]
plt.plot(ename,sal,marker='d')
plt.xlabel('Emlpoyee Name')
plt.ylabel('Salary')
plt.title('Employee Salary Details')
plt.savefig('simple.pdf')
plt.show()
Part C
3. Write a SQL Command to do the following 7M
i. create a table called products based on the following given data.
Columns/Field Datatype Key
Pid Int Primary key
Pname Varchar(20)
Category Varchar(15)
Stock Int
Comm Decimal(6,2)
Mfgdate date
ANSWERS
Page 2 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics
ANSWERS Practices (065)
iv. Display product name by deleting leading/trailing spaces if there are any
ANSWERS
mysql> select ltrim(pname) from products;
+--------------+
| ltrim(pname) |
+--------------+
| Phone |
| Shoe |
| Chair |
+--------------+
3 rows in set (0.00 sec)
mysql> select rtrim(pname) from products;
+--------------+
| rtrim(pname) |
+--------------+
| Phone |
| Shoe |
| Chair |
+--------------+
Page 3 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: vi.
XII Sub: Informatics Practices (065)
Page 4 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
SET 2
PART A
1. Consider the following Series Class and answer the questions.
A 45
B 36
C 27
D 35
(i) Write python code to create above series Class using list
(ii) Write a statement to delete element whose index is ‘B’
(iii) Write a statement to add one element with 54 as value and index as ‘E’ 3M
i) import pandas as pd
Class=pd.Series([45,26,37,25],index =['A','B','C','D'])
print(Class)
A 45
B 26
C 37
D 25
dtype: int64
iii) Class['E']= 54
print(Class)
C 37
D 25
E 54
dtype: int64
PART B
2. Write program in python to create a bar chart that represents boys and girls
strength of classes from 8 to 12, and also set the name to x-axis as class, y-axis as
count and title as 'Classs wise Boys and Girls count'. Also save graph as simple.pdf.
Class=[8,9,10,11,12]
Boys=[35,30,40,45,42]
Girls=[20,25,42,38,40]
Page 1 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
ANSWER
import matplotlib.pyplot as plt
import numpy as np
Class=[8,9,10,11,12]
Boys=[35,30,40,45,42]
Girls=[20,25,42,38,40]
dummy=np.arange(5)
plt.bar(dummy,Boys,label='Boys',width=0.4)
plt.bar(dummy+0.4,Girls,label='Girls',width=0.4)
plt.xlabel('Class')
plt.ylabel('Count')
plt.title('Classs wise Boys and Girls count')
plt.savefig('simple.pdf')
plt.xticks(dummy,Class)
plt.legend(loc=2)
plt.show()
5M
PART C
3.Consider the following two tables Employee and Department, and write SQL commands
to the following 7M
i. Create Department table as per above given data by applying primary key on
Deptno column
ii. Create Employee table as per above given data by applying primary on eno
column and foreign key on deptno column with reference to Department table
deptno column
Page 2 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
answer
vi. Display Employee and their HOD name who are working in CS department
vii. Display Employee and their department name whose hod is Riya
SET 3
PART A
3. Write a python code to do the following with resoect to DataFrame df,
3M
Page 3 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
PART B
2. Write program in python to create a histogram that represents runs of batman in
different matches in the form of ranges, and also set the name to x-axis as runs
range, y-axis as runs and title as batsman score. Also save graph as simple.pdf,
runs=[81,85,65,42,57,72,85,99,94,72,66,67,76] bins=[50,60,70,80,90,100] 5M
import matplotlib.pyplot as plt
Page 4 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
runs=[81,85,65,42,57,72,85,99,94,72,66,67,76]
bins=[50,60,70,80,90,100]
plt.hist(runs,bins,rwidth=0.5)
plt.xlabel('Runs Range')
plt.ylabel('Runs')
plt.title('Batsman Score')
plt.savefig('simple.pdf')
plt.xticks(bins)
PART C
Page 5 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
select name from students1;
+----------+
| name |
+----------+
| srinath |
| Supriya |
| Chandhan |
+----------+
iii. Display Humanities student details who are coming from Nagpur.
select * from students1 where stream='humanities' and city='nagpur';
+--------+---------+------------+--------+------------+---------+
| Rollno | Name | DOB | City | Stream | Fee |
+--------+---------+------------+--------+------------+---------+
| 2 | Supriya | 2016-09-25 | Nagpur | Humanities | 5454.50 |
+--------+---------+------------+--------+------------+---------+
iv. Display student names whose fee is in between 2000 to 3000 (including both).
select name from students1 where fee between 2000 and 3000;
+---------+
| name |
+---------+
| srinath |
+---------+
OR
select name from students1 where fee>=2000 and fee<= 3000;
+---------+
| name |
+---------+
| srinath |
+---------+
Page 6 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
vi. Display student names as per ascending order of their fee.
select name from students1 order by fee;
+----------+
| name |
+----------+
| Chandhan |
| srinath |
| Supriya |
+----------+
NOT THERE
(ii)Display total price of all products
(iii) Display total number of products in each category if that category has at least 3
products
SET 4
Part A
1.(i) Write a program in Python Pandas to create a series named as “stu_marks” which
stores marks of 4 subjects of a student in class XII B of your school.Assume that student is
studying class XII and have 67,72,85,83 marks in Maths, English, Hindi, IP respectively and
pandas library has been imported as pd.
(ii) Write a python statement to display IP marks.
(iii) Write a python statement to display first three items from stu_marks 3M
import pandas as pd
stu_marks= pd.Series([67,72,85,83], index=["Maths" , "English", "Hindi", "IP"])
print(stu_marks)
Output
Maths 67
English 72
Hindi 85
IP 83
(ii)
print(stu_marks['IP'])
Output
83
(iii)
print(stu_marks.head(3))
Output
Maths 67
English 72
Hindi 85
dtype: int64
Page 7 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
Part B
2.Write program in python to create a line chart with the given data and also set the
name to . x-axis as ename, y axis as sal, title as simple. Also save graph as simple.pdf
ename=[‘Hari’,’Riya’,’Chandhan’,’Joe’,’Mita’]
sal=[4000,6000,5000,3500,8000]
Part c
3.Consider the following two tables Employee and Department, and write SQL commands
to the following 7M
i. Create Department table as per above given data by applying primary key on
Deptno column
ii. Create Employee table as per above given data by applying primary on eno
column and foreign key on deptno column with reference to Department table
deptno column
Page 8 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
vi. Display Employee and their HOD name who are working in CS department
vii. Display Employee and their department name whose hod is Riya
Page 9 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
SET 5
PART A
4. Write python code to create the following DataFrame Stock 3M
PART B
2.Write program in python to create a bar chart that represents boys and girls
strength of classes from 8 to 12, and also set the name to x-axis as class, y-axis as
count and title as 'Classs wise Boys and Girls count'. Also save graph as simple.pdf.
Class=[8,9,10,11,12]
Boys=[35,30,40,45,42] Girls=[20,25,42,38,40] 5M
Answer
import matplotlib.pyplot as plt
import numpy as np
Class=[8,9,10,11,12]
Boys=[35,30,40,45,42]
Girls=[20,25,42,38,40]
Page 10 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
dummy=np.arange(5)
plt.bar(dummy,Boys,label='Boys',width=0.4)
plt.bar(dummy+0.4,Girls,label='Girls',width=0.4)
plt.xlabel('Class')
plt.ylabel('Count')
plt.title('Classs wise Boys and Girls count')
plt.savefig('simple.pdf')
plt.xticks(dummy,Class)
plt.legend(loc=2)
plt.show()
PART C
3. Write a SQL Command to do the following 7M
i. create a table called products based on the following given data.
Columns/Field Datatype Key
Pid Int Primary key
Pname Varchar(20)
Category Varchar(15)
Stock Int
Comm Decimal(6,2)
Mfgdate date
ANSWERS
insert into products values(1,'Phone','Electronics',20,350.23,'2024-09-27');
insert into products values(2,'Shoe','Apparel',30,200.45,'2023-10-15');
insert into products values(3,'Chair','Home',15,40.23,'2024-11-22');
Page 11 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
+-------------------+
| substr(pname,1,2) |
+-------------------+
| Ph |
| Sh |
| Ch |
+-------------------+
xi. Display product name by deleting leading/trailing spaces if there are any
ANSWERS
mysql> select ltrim(pname) from products;
+--------------+
| ltrim(pname) |
+--------------+
| Phone |
| Shoe |
| Chair |
+--------------+
3 rows in set (0.00 sec)
mysql> select rtrim(pname) from products;
+--------------+
| rtrim(pname) |
+--------------+
| Phone |
| Shoe |
| Chair |
+--------------+
Page 12 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
SET 6
Part A
(i) Write python code to create the above following DataFrame emp ,
(ii) Add a new column called Dept with values ['Maths','Phy','Chem','Comp','Phy']
(iii) Delete a column called Dept.
import pandas as pd
d={'Name':['Anya','Smith','Bina','Vinay','Arjun'],
'Job':['Clerk','Analyst','Analyst','Clerk','Salesman'],
'Sal':[500,550,480,475,540]
}
emp=pd.DataFrame(d)
print(emp)
(ii) emp['Dept']=['Maths','Phy','Chem','Comp','Phy']
(iii) emp['HRA']=emp['Sal']*0.1
(iv) emp['Total']=emp['Sal']+emp['HRA']
(v)
del emp[‘Total’]
(or)
emp.drop([‘Total’],axis=1,inplace=True)
(or)
emp.drop(‘Total’,axis=1,inplace=True)
(or)
emp=emp=emp.drop(‘Total’,axis=1)
Page 13 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
Part B
2. Write program in python to create a histogram that represents runs of batman in
different matches in the form of ranges, and also set the name to x-axis as runs
range, y-axis as runs and title as batsman score. Also save graph as simple.pdf,
runs=[81,85,65,42,57,72,85,99,94,72,66,67,76] bins=[50,60,70,80,90,100] 5M
Part C
3.Write SQL commands to do the following 7M
Create the table students with following information.
Column Datatype Key
Rollno Int Primary Key
Name Varchar(20)
DOB Date
City Varchar(16)
Stream Varchar(10)
Fee Decimal(6,2)
ANSWERS
create table students1( Rollno Int Primary Key,Name Varchar(20),DOB Date,City
Varchar(16),Stream Varchar(10),Fee Decimal(6,2));
Page 14 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XIIinsert into Sub: Informatics
students1 Practices (065)
values(1,'srinath','2015-11-
05','Bangalore','Science',2344.75);
select name from students1 where fee between 2000 and 3000;
+---------+
| name |
+---------+
| srinath |
+---------+
OR
select name from students1 where fee>=2000 and fee<= 3000;
+---------+
| name |
+---------+
| srinath |
+---------+
Page 15 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)
xi. Display all student details whose name starts with s
select * from students1 where name like 's%';
+--------+---------+------------+-----------+------------+---------+
| Rollno | Name | DOB | City | Stream | Fee |
+--------+---------+------------+-----------+------------+---------+
| 1 | srinath | 2015-11-05 | Bangalore | Science | 2344.75 |
| 2 | Supriya | 2016-09-25 | Nagpur | Humanities | 5454.50 |
+--------+---------+------------+-----------+------------+---------+
Page 16 of 20