0% found this document useful (0 votes)
24 views20 pages

IP Class 12 Practical Questions

Uploaded by

kumari.pinky88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views20 pages

IP Class 12 Practical Questions

Uploaded by

kumari.pinky88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Sri Chaitanya Educational Institutions, Karnataka

Class: XII Sub: Informatics Practices (065)


SET 1
Part A
1. Write python code for the following with respect to DataFrame marks, 3M

(i) Write the code to create dataframe marks


(ii) Display first two rows.
(iii) Add a new column called Total which is sum of all Tests.

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

mysql> use db10;


Database changed

mysql> create table products(Pid Int Primary


key,Pname Varchar(20),Category Varchar(15),Stock
Int,Comm Decimal(6,2),Mfgdate date);

ii. insert the following data into the products table as


(1,'Phone','Electronics',35000,20,350.23,'2024-09-27')
(2,'Shoe','Apparel',2500,30,200.45,'2023-10-15')
(3,'Chair','Home',4400,15,40.23,'2024-11-22')

Page 2 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics
ANSWERS Practices (065)

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');

iii. Display first two characters in every product name


ANSWERS
select substr(pname,1,2) from products;
OR
select left(pname,2) from products;
+-------------------+
| substr(pname,1,2) |
+-------------------+
| Ph |
| Sh |
| Ch |
+-------------------+

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 |
+--------------+

v. Display the position of ‘nic’ in product category


select instr(category,'nic') from products;
+-----------------------+
| instr(category,'nic') |
+-----------------------+
| 8|
| 0|
| 0|
+-----------------------+

Page 3 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: vi.
XII Sub: Informatics Practices (065)

vii. Display product names and category manufactured in February month


select pname, category from products where monthname(mfgdate)='february';

viii. Display all products manufactured month name

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

ii) del Class['B']

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

create table department(deptno int primary key,deptname varchar(10),HOD


varchar(10));

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

create table employee1(eno int primary key,ename varchar(10),deptno int, sal


float,foreign key(deptno) references department(deptno));

iii. Insert data[40,cn,hari,][20,AI,shyam,][30,ML,Ananya] into Department table


insert into department values(40,'cn','hari');
insert into department values(20,'AI','shyam');
insert into department values(30,'ML','Ananya');

iv. Insert data [1,riya,10,500][2,madhav,20,550][3,krish,20,400]into Employee table


insert into employee1 values(1,'riya',30,500);
insert into employee1 values(2,'madhav',20,550);
insert into employee1 values(3,'krish',40,400);

v. Display Employee and their Department name

select ename, deptname from employee1 e, department d where


e.deptno=d.deptno;
+--------+----------+
| ename | deptname |
+--------+----------+
| madhav | AI |
| riya | ML |
| krish | cn |
+--------+----------+

vi. Display Employee and their HOD name who are working in CS department

select ename,hod from employee1, department where


employee1.deptno=department.deptno and deptname='cs';

vii. Display Employee and their department name whose hod is Riya

select ename,deptname from employee1, department where


employee1.deptno=department.deptno and hod='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)

(i) Write python code to create above dataframe df


(ii) Display total number of boys students.
(iii) Display class strength if it has more than 30 girls.
import pandas as pd
d={'Boys':[35,30,40,45,42],'Girls':[20,25,42,38,40]}
df=pd.DataFrame(d,index=['VIII','IX','X','XI','XII'])
print(df)
(i)
print(df['Boys'].sum())
(or)
L1=df['Boys'].tolist()
print(sum(L1))
Output
192
(ii)
print(df['Girls'].sum())
(or)
L2=df['Girls'].tolist()
print(sum(L2))
Output
165
(iii)
print(df['Boys'].sum()+df['Girls'].sum())
(or)
L3=df['Boys'].tolist()+df['Girls'].tolist()
print(sum(L3))
Output
357

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

3. Write SQL commands to do the following 7M


(i) 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)

create table students1( Rollno Int Primary Key,Name Varchar(20),DOB Date,City


Varchar(16),Stream Varchar(10),Fee Decimal(6,2));

i. insert the data into the students table


[1, srinath,2015-11-05, Bangalore,Science,2344.75]
[2, Supriya,2016-09-25 ,Nagpur,Humanities,5454.50]
[3, Chandhan,2018-12-18, Delhi NCR,Arts,1234.56]

insert into students1 values(1,'srinath','2015-11-


05','Bangalore','Science',2344.75);

insert into students1 values(2,'Supriya','2016-09-


25','Nagpur','Humanities',5454.50);

insert into students1 values(3,'Chandhan','2018-12-18','Delhi


NCR','Arts',1234.56);

ii. Display all student names

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 |
+---------+

v. 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 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]

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.savefig('simple.pdf')
plt.show()

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

create table department(deptno int primary key,deptname varchar(10),HOD


varchar(10));

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)

create table employee1(eno int primary key,ename varchar(10),deptno int, sal


float,foreign key(deptno) references department(deptno));

iii. Insert data[40,cn,hari,][20,AI,shyam,][30,ML,Ananya] into Department table


insert into department values(40,'cn','hari');
insert into department values(20,'AI','shyam');
insert into department values(30,'ML','Ananya');

iv. Insert data [1,riya,10,500][2,madhav,20,550][3,krish,20,400]into Employee table


insert into employee1 values(1,'riya',30,500);
insert into employee1 values(2,'madhav',20,550);
insert into employee1 values(3,'krish',40,400);

v. Display Employee and their Department name

select ename, deptname from employee1 e, department d where


e.deptno=d.deptno;
+--------+----------+
| ename | deptname |
+--------+----------+
| madhav | AI |
| riya | ML |
| krish | cn |
+--------+----------+

vi. Display Employee and their HOD name who are working in CS department

select ename,hod from employee1, department where


employee1.deptno=department.deptno and deptname='cs';

vii. Display Employee and their department name whose hod is Riya

select ename,deptname from employee1, department where


employee1.deptno=department.deptno and hod='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

(i) Write the code to create dataframe Stock


(ii) Add a new row with name as Diary with price 12.
(iii) delete row whose index is 4.
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)

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

create table products(Pid Int Primary key,Pname


Varchar(20),Category Varchar(15),Stock Int,Comm
Decimal(6,2),Mfgdate date);

ix. insert the following data into the products table as


(1,'Phone','Electronics',35000,20,350.23,'2024-09-27')
(2,'Shoe','Apparel',2500,30,200.45,'2023-10-15')
(3,'Chair','Home',4400,15,40.23,'2024-11-22')

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');

x. Display first two characters in every product name


ANSWERS
select substr(pname,1,2) from products;
OR
select left(pname,2) from products;

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 |
+--------------+

xii. Display the position of ‘nic’ in product category


select instr(category,'nic') from products;
+-----------------------+
| instr(category,'nic') |
+-----------------------+
| 8|
| 0|
| 0|

xiii. Display product names and category manufactured in February month


select pname, category from products where monthname(mfgdate)='february';

xiv. Display all products manufactured month name

Page 12 of 20
Sri Chaitanya Educational Institutions, Karnataka
Class: XII Sub: Informatics Practices (065)

SET 6
Part A

1. write python code to create the following DataFrame 3M

(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

import matplotlib.pyplot as plt


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
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));

vii. insert the data into the students table


[1, srinath,2015-11-05, Bangalore,Science,2344.75]
[2, Supriya,2016-09-25 ,Nagpur,Humanities,5454.50]
[3, Chandhan,2018-12-18, Delhi NCR,Arts,1234.56]

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);

insert into students1 values(2,'Supriya','2016-09-


25','Nagpur','Humanities',5454.50);

insert into students1 values(3,'Chandhan','2018-12-18','Delhi


NCR','Arts',1234.56);

viii. Display all student names


select name from students1;
+----------+
| name |
+----------+
| srinath |
| Supriya |
| Chandhan |
+----------+
ix. 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 |
+--------+---------+------------+--------+------------+---------+
x. 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 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 |
+--------+---------+------------+-----------+------------+---------+

xii. Display student names as per ascending order of their fee.


select name from students1 order by fee;
+----------+
| name |
+----------+
| Chandhan |
| srinath |
| Supriya |
+----------+

Page 16 of 20

You might also like