Study Material IP XII
Study Material IP XII
1. What is Numpy?
2. Why Numpy is used over Lists?
3. Write a Numpy program to get the Numpy version ?
4. Write Numpy Program to test whether none of the elements of a given array is zero.
5. Write a Numpy program to create an array of 10 zeros, 10 ones and 10 fives.
6. Write a Numpy program to find the number of rows and columns of the given
matrix.
7. Write a Numpy program to compute sum of all elements, sum of each column and
sum of
each row of a matrix.
8. Write a Numpy program to convert a given array into a list and then convert it into a
array
again.
9. Write a Numpy program to create a 1 D array with values from 0 to 9
10. Write a NumPy program to reverse an array (first element
becomes last). Original array:
[12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37]
Reverse array:
[37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12]
11. Write a NumPy program to create a 2d array with 1 on the border and 0 inside.
Expected Output:
Original array:
[[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]]
1 on the border and 0 inside in the
array [[ 1. 1. 1. 1. 1.]
[ 1. 0. 0. 0. 1.]
[ 1. 0. 0. 0. 1.]
[ 1. 0. 0. 0. 1.]
[ 1. 1. 1. 1. 1.]]
14. Suppose a data frame contains information about student having columns rollno, name,
class and section. Write the code for the following:
(i) Add one more column as fee
(ii) Write syntax to transpose data frame.
(iii) Write python code to delete column fee of data frame.
(iv) Write the code to append df2 with df1
15. Assume following data is stored in data frame named as df1
Write following commands:
(i) Find total sales per state
(ii) find total sales per employee
(iii) find total sales both employee wise and state wise
(iv)find mean, median and min sale state
wise (v)find maximum sale by individual
Name of
Employee Sales Quarter State
RSahay 125600 1 Delhi
Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
19. Write a Pandas program to select the rows where the number of attempts in the
examination is greater than 2.
Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
20. Write a Pandas program to select the rows the score is between 15 and 20 (inclusive).
Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
21. Write a Pandas program to select the specified columns and rows from a given
DataFrame. Select 'name' and 'score' columns in rows 1, 3, 5, 6 from the following data
frame.
Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
Answers
1. Pandas Series is a one-dimensional labeled array capable of holding data of any type
(integer, string, float, python objects, etc.) . The axis labels are collectively called index.
Pandas Series is nothing but a column in an excel sheet.
2. Python | Pandas DataFrame. Pandas DataFrame is two-dimensional size-mutable,
potentially heterogeneous tabular data structure with labeled axes (rows and columns).
A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion
in rows and columns.
3. Import pandas as
pd
Df=pd.DataFrame()
Print(df)
4. Df=df1.fillna(0)
5. A quartile is a type of quantile. The first quartile is defined as the middle number
between the smallest number and the median of the data set. The second quartile is
the median of the data. The third quartile is the middle value between the median and
the highest value of the data set
Pandas dataframe.quantile() function return values at the given quantile over requested
axis, a numpy.percentile. Note : In each of any set of values of a variate which divide a
frequency distribution into equal groups, each containing the same fraction of the total
population.
6. Data pivioting is summarization technique to rearrange the coluns and rows in a
report so as to view data from different prospectives.
Pandas library makes available two functions for pivoting – the pivot() and pivot_table()
function.
7. Dataframe.aggregate() function is used to apply some aggregation across one or
more column. Aggregate using callable, string, dict, or list of string/callables. Most
frequently used aggregations are: sum: Return the sum of the values for the requested
axis. min: Return the minimum of the values for the requested axis.
8. pivot() is used for pivoting without aggregation. Therefor, it can’t deal with duplicate
values for one index/column pair.
9. import pandas as pd
ds = pd.Series([2, 4, 6, 8,
10]) print(ds)
10. The rename() function renames the existing indexes in dataframe whereas
reindex() function is used to change the order or existing lables in dataframe
11. The method pipe() creates a pipe and returns a pair of file descriptors (r, w) usable
for reading and writing, respectively.
12. import pandas as pd
d={‘Name”:[‘RAJIV’,’SAMEER’,’KAPIL’],
’Age’:[20,35,45],’Designation’:[‘CLERK’,’MANAGER’,’ACCOUNTANT’]}
df=pd.DataFrame(d)
13.
a. print(“Maximum marks = “ ,
DF[“Marks”].max())
print(“Minimum marks = “ , DF[“Marks”].min())
b. print(“Sum of marks = “ , DF[“Marks”].sum())
c. print(“Mean of Age = “,DF[“Age”].mean())
print(“Mode of Age = “,DF[“Age”].mode())
d. print(“No of rows = “,DF.count())
14.
I. Df1[‘fee’]=([100,200,300])
II. Df1=Df1.T
III. Df2.pop(‘fee’)
Df2=Df2.append(Df1)
15.
(i) pv1=pd.pivot_table(dfN,index=[‘State’], values=[‘Sales’],aggfunc=np.sum)
(ii) pv1=pd.pivot_table(dfN,index=[‘Name of Employee’], values=[‘Sales’],aggfunc=np.sum)
(iii)pv1=pd.pivot_table(dfN,index=[‘Name of
Employee’,’State’],values=[‘Sales’],aggfunc=np.sum)
(iv) pv1=pd.pivot_table(dfN,index=[‘State’],values=[‘Sales’],aggfunc=[np.mean,np.
min,np. max])
pv1=pd.pivot_table(dfN,index=[‘Name of Employee’],values=[‘Sales’],aggfunc=np.max)
16. #df1
output a b
first 1 2
second 5 10
#df2 output
a b1
first 1 NaN
second 5 NaN
17. import pandas as pd
df = pd.DataFrame({'X':[78,85,96,80,86], 'Y':[84,94,89,83,86],'Z':[86,97,96,72,83]});
print(df)
18. import pandas as
pd import numpy as
np
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(exam_data ,
index=labels) print(df)
df = pd.DataFrame(exam_data , index=labels)
print("Number of attempts in the examination is greater than
2:") print(df[df['attempts'] > 2])
20. import pandas as
pd import numpy as
np
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(exam_data , index=labels)
print("Rows where score between 15 and 20
(inclusive):") print(df[df['score'].between(15, 20)])
21. import pandas as
pd import numpy as
np
df = pd.DataFrame(exam_data ,
index=labels) print("Select specific
columns and rows:") print(df.iloc[[1, 3, 5,
6], [1, 3]])
PLOTTING WITH
PYPLOT
Q1. What is data visualization? What is its significance?
Q2 What is Boxplot? How do you create it in Pyplot? Explain with an
example. Q3. What is quantile? Explain.
Q4. What is a cumulative histogram? How do you create it?
Q5. Given two arrays namely arr1 and arr2 each having 5 values. Create a scatter chart
so that each data points gets a different color, different size. Keep the marker style as
square.
Q6. What will be the output of the following code :
import matplotlib.pyplot as
plt plt.plot([1,2,3],[4,5,1])
plt.show()
Q9. Write a Python program to draw a line as shown below using given axis values with
suitable label in the x axis , y axis and a title.
Q10. Write a Python program to draw line charts of the financial data of Alphabet Inc.
between October 3, 2016 to October 7, 2016.
Sample Financial data
(fdata.csv):
Date,Open,High,Low,Close
10-03-16,774.25,776.065002,769.5,772.559998
10-04-16,776.030029,778.710022,772.890015,776.429993
10-05-16,779.309998,782.070007,775.650024,776.469971
10-06-16,779,780.47998,775.539978,776.859985
10-07-16,779.659973,779.659973,770.75,775.080017
The code snippet gives the output shown in the following screenshot:
Q11. Write a Python program to plot two or more lines on same plot with suitable
legends of each line.
The code snippet gives the output shown in the following screenshot:
Q.12 Is there any function in pyplot to create frequency polygon? If no how can we create it.
SOLUTIONS
Ans 1:
Data visualization is the act of taking information (data) and placing it into a visual
context, such as a map or graph. Data visualizations make big and small data easier for
the human brain to understand, and visualization also makes it easier to detect patterns,
trends, and outliers in groups of data.
Ans 2:
A Box Plot is the visual representation of the statistical five number summary of a given
data set.
A Five Number Summary includes:
• Minimum
• First Quartile
• Third Quartile
• Maximu
m
Example
value1 = [72,76,24,40,57,62,75,78,31,32]
import matplotlib.pyplot as plt
A1 = [72,76,24,40,57,62,75,78,31,32]
box=plt.boxplot(A
1) plt.show()
Ans 3:
The word “quantile” comes from the word quantity. Means a quantile is where a sample
is divided into equal-sized subgroups. It can also refer to dividing a probability
distribution into areas of equal probability
Ans 4:
A cumulative histogram is a mapping that counts the cumulative number of observations
in all of the bins up to the specified bin.
Example: A = [63, 65, 67, 69, 71]
plt.hist(A, cumulative = True)
Ans 5:
import matplotlib.pyplot as
plt ar1 =
[2,4,6,8,10,12,14,16]
ar2 = [5,10,15,20,25,30,35,40]
colors = [ 'r', 'b', 'g', 'y',
'k'] sizes =
[20,30,50,45,60]
plt.scatter(ar1,ar2,c = colors, s = sizes, marker = 's')
Ans 6:
Ans 7:
A = [63, 65, 67, 69, 71, 71, 72, 74, 75, 78, 79, 79, 80, 81, 83]
(i) plt.boxplot(A1, bins = 5, vert = False)
(ii) plt.boxplot(A1, bins = 5, vert = True)
Ans 8:
from matplotlib import pyplot as
plt x = [5,8,10]
y = [12,16,6]
x2 = [6,9,11]
y2 = [6,15,7]
plt.bar(x, y, align='center')
plt.bar(x2, y2, color='g',
align='center') plt.title('Epic Info')
plt.ylabel('Y
axis')
plt.xlabel('X
axis')
plt.show()
Ans 9:
import matplotlib.pyplot as
plt # x axis values
x = [1,2,3]
# y axis
values y =
[2,4,1]
# Plot lines and/or markers to the
Axes. plt.plot(x, y)
# Set the x axis label of the current
axis. plt.xlabel('x - axis')
# Set the y axis label of the current
axis. plt.ylabel('y - axis')
# Set a title
plt.title('Sample
graph!') # Display a
figure. plt.show()
Ans 10:
import matplotlib.pyplot as
plt import pandas as pd
df = pd.read_csv('fdata.csv', sep=',', parse_dates=True,
index_col=0) df.plot()
plt.show()
Ans 11:
import matplotlib.pyplot as
plt # line 1 points
x1 = [10,20,30]
y1 = [20,40,10]
# plotting the line 1 points
plt.plot(x1, y1, label = "line
1") # line 2 points
x2 = [10,20,30]
y2 = [40,10,30]
# plotting the line 2 points
plt.plot(x2, y2, label = "line
2") plt.xlabel('x - axis')
# Set the y axis label of the current
axis. plt.ylabel('y - axis')
# Set a title of the current axes.
plt.title('Two or more lines on same plot with suitable
legends ') # show a legend on the plot
plt.legend()
# Display a
figure.
plt.show()
Ans 12
There is not any pyplot function to create frequency polygon. We can create it by
1. Plot a histrogram from the data
2. Mark a single point at the midpoint of an interval/bin
3. Draw straight lines to connect the adjacent points
4. Connect first data point to the midpoint of previous interval on xais
5. Connect last data point to the midpoint of the following interval on x asis
For example we have a series name com that stores some 1000 values Plotting a
step histogram from the same
Pl.hist(com,bin-10,histtype=’step’)
Joining midpoint of each set of adjacent bins to create frequency polygon
The output of every Sprint is an Increment of a Done Software which can be
shipped off to the end user for usage. An item is only marked done if it matches
the definition of done.
Topic : MySQL : Revision Tour, More on SQL
EMP TABLE
Column Name Type SIZ Constraint Description
E
EMPNO INTEGER PRIMARY KEY EMPLOYEE NUMBER
ENAME VARCHAR 20 NOT NULL EMPLOYEE NAME
JOB CHAR 10 DESIGNATION
MGR INTEGER RESPECTIVE MANGER’S
EMPNO
HIREDATE DATE DATE OF JOINING
SAL DECIMAL 9,2 >0 SALARY
COMM INTEGER COMMISSION
DEPTNO INTEGER FOREIGN KEY DEPARTMENT NUMBER
DEPT
DEPTNO
Q 12 Amit creates a database name contacts but he is not able to create the table.
What command should be used before creating the table?
Q13 A table Student has 4 rows and 2 Column and another table has 3 rows and 4
columns. How many rows and columns will be there if we obtain the Cartesian product
of these two tables?
Q14 Mr. Sanghi created two tables with City as Primary Key in Table1 and Foreign key
in Table2 while inserting row in Table2 Mr Sanghi is not able to enter value in the column
City. What is the possible reason for it?
Q15. What is difference between curdate() and date() functions?
Q16. There is column salary in table employee. The following two statements are giving
different outputs. What may be the possible reasons?
Select count(*) from employee select count(salary) from employee
Q17. Give One difference between Rollback and Commit?
Q18. What is View?
Q19. TABLE: GRADUATE
S.NO NAME STIPEND SUBJECT AVERAGE DIV.
1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMP. Sc. 68 I
3 DIVYA 300 CHEMISTRY 62 I
4 REKHA 350 PHYSICS 63 I
5 ARJUN 500 MATHS 70 I
6 SABINA 400 CEHMISTRY 55 II
7 JOHN 250 PHYSICS 64 I
8 ROBERT 450 MATHS 68 I
9 RUBINA 500 COMP. Sc. 62 I
10 VIKAS 400 MATHS 57 II
(a) List the names of those students who have obtained DIV I sorted by NAME.
(b) Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend
received in a year assuming that the STIPEND is paid every month.
(c.) To count the number of students who are either PHYSICS or COMPUTER SC graduates.
(d) To insert a new row in the GRADUATE table 11,”KAJOL”, 300, “COMP. SC.”, 75, 1
(e) Give the output of following sql statement based on table GRADUATE:
i. Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”;
ii. Select SUM(STIPEND) from GRADUATE WHERE div=2;
iii. Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;
iv. Select COUNT(distinct SUBDJECT) from GRADUATE;
Assume that there is one more table GUIDE in the database as shown below:
Table: GUIDE
MAINAREA ADVISOR
PHYSICS VINOD
COMPUTER SC ALOK
CHEMISTRY RAJAN
MATHEMATICS MAHESH
Table: TRANSACT
(i) To display details of all transactions of TYPE Deposit from Table TRANSACT
(ii) To display the ANO and AMOUNT of all Deposits and Withdrawals done in the
month of October 2017 from table TRANSACT.
(iii) To display the last date of transaction (DOT) from the table TRANSACT for the
Accounts having ANO as 103.
(iv) To display all ANO, ANAME and DOT of those persons from tables ACCOUNT and
TRANSACT who have done transactions less than or equal to 3000.
(v) SELECT ANO, ANAME FROM ACCOUNT WHERE ADDRESS NOT IN ('CHENNAI',
'BANGALORE'); (vi)SELECT DISTINCT ANO FROM TRANSACT;
(vii) SELECT ANO, COUNT(*), MIN(AMOUNT) FROM TRANSACT GROUP BY ANO
HAVING COUNT(*)> 1;
(viii) SELECT COUNT(*), SUM(AMOUNT) FROM TRANSACT WHERE DOT <= '2017-06-01';
(ix) identify the foreign key.
SOLUTIONS
Ans 1. A database management system (DBMS) is system software for creating and
managing databases. The DBMS provides users and programmers with a systematic
way to create, retrieve, update and manage data
Ans 2. A data model refers to a set of concepts to describe the structure of a database,
and certain constraints (restrictions) that the database should obey. The four data
model that are used for database management are :
1. Relational data model : In this data model, the data is organized into tables (i.e. rows
and columns). These tables are called relations. 2. Hierarchical data model 3. Network
data model
4. Object Oriented data model
Ans 3. Data redundancy means duplication of data. Itcauses duplicate
dataatdifferentlocations which destroys the integrityof the database and wastage of
storage space.
Ans 4.
Internal Level Conceptual Level External Level
Describes what data
Describes how the data is
are actually stored Concerned with the data is
actually stored on the
inthedatabase and viewed by individual users.
storage medium.
relationship
existing
among data.
At this level, complex low- At this level, the database is Only a part of the database
level
described logically in terms relevant to the users is
data structure are described provided to them through this
of simple data-structures.
in details.
Ans 5. Data independence is the ability to modify a scheme definition in one level
without affecting a scheme definition in ahigher level. Data independence types are
1. Physical Data Independence has ability to modify the scheme followed at the
physical level without affecting thescheme followed atthe conceptual level.
2. Logical Data Independence has ability to modify the conceptual scheme
without causing any changes in the schemes followed at view levels.
Ans 6. SQL is a language that enables you to create and operate on relational
databases, which are sets of related information stored in tables.
Ans 7
1. Relation : A table storing logically related data is called a Relation.
2. Tuple : A row of a relation is generally referred to as a tuple.
3. Attribute : A column of a relation is generally referred to as an attribute.
4. Degree : This refers to the number of attributes in a relation.
5. Cardinality : This refers to the number of tuples in a relation.
6. Primary Key : This refers to a set of one or more attributes that can uniquely identify
tuples within the relation.
7. Candidate Key : All attribute combinations inside a relation that can serve as primary
key are candidate keys as these are candidates for primary key position.
8. Alternate Key : A candidate key that is not primary key, is called an alternate key.
9. Foreign Key : A non-key attribute, whose values are derived from the primary key of
some other table, is known as foreign key in its current table.
1. Domain constraints
Domain constraints can be defined as the definition of a valid set of values for an
attribute. The data type of domain includes string, character, integer, time, date,
currency, etc. The value of the attribute must be available in the corresponding
domain.
Example:
4. Key constraints
Keys are the entity set that is used to identify an entity within its entity set uniquely.
An entity set can have multiple keys, but out of which one key will be the primary key. A
primary key can contain a unique and null value in the relational table.
Example:
Ans 10 .
Create table dept(deptno integer Primary Key,dname integer(20), loc varchar(10));
Create table emp(empno integer Primary Key, Ename varchar(20) NOT NULL, job
Char(10), mgr integer, hiredate date, sal decimal(9,2) check(sal>0),comm integer,
deptno integer references dept(deptno) on delete cascade);
Ans 11.
a) select * from emp where deptno=20 or job=’salesman’;
b) select empno,ename from emp where job=’Manger’;
c) select * from emp where deptno=20 and job=’clerk’;
d) select * from emp where hiredate<’2014-09-01’;
e) select * from emp where job!=’manager’;
f) select * from emp where empno in(7369,7521,7839,7934,7788);
g) select empno, ename from emp where empno between 1000 and 2000;
h) select ename from emp where hiredate not between ‘2014-06-30’ and ’2014-12-31’;
i) select distinct(job) from emp;
j) select * from emp where comm is NULL;
k) select ename from emp where ename like ‘S%’;
l) select ename from emp where ename like’ ’;
m) select ename from emp where ename like ‘_I%’;
n) select empno,ename,sal from emp order by sal;
o) select empno,ename from emp order by hiredate desc;
p) select ename, sal,sal*,5 as “hra”,sal*.1 as “pf”, sal*.3 as “da”, sal+sal*.5+sal*.3-sal*.1 as
“gross” order by sal+sal*.5+sal*.3-sal*.1;
q) select count(*) from emp ;
r) select count(distinct job) from emp;
s) select depnto,sum(sal) from emp group by deptno;
t) select job, count(*) from emp group by job order by count(*) desc;
u) select sum(sal),max(sal),min(sal),avg(sal) from where deptno=20 emp group by job;
v) select depnto,job,deptno from emp group by deptno,job;
w) select avg(sal) from emp group by deptno having count(*)>5;
x) select sum(sal),max(sal),min(sal),avg(sal) from emp where deptno=20 group by
job having avg(sal)>1000 order by sum(sal);
y) select empno,ename, e.deptno,dname from emp e, dept d where e.deptno=d.deptno;
z) select empno,ename, sal, sal+ifnull(comm,0) as “total salary”
from emp; aa) alter table emp add column address varchar(20);
bb) alter table emp add constraing pk_1 Primay key(empno);
cc) alter table emp add constraint fk_1 Foreign Key deptno references (dept(deptno)
on delete cascade)
dd) alter table emp Modify sal
decimal(15,2); ee) alter table emp drop
column address;
Ans 12
Use Contacts
Ans 13
12 rows and 6 columns
Ans 14
Mr Sanghi was trying to enter the name of City in Table2 which is not present in Table1
i.e. Referential Integrity ensures that value must exist in referred table.
Ans 15
curdate() returns the current date whereas date() extracts the date part of a date.
Ans 16
The possible reason is that the salary filed may contain null values so count(salary)
will not count that record.
Ans 17
Rollback command is used to end the current transaction and Undo all the changes we
made since current transaction begin While Commit is used to make all changes
permanent to underlying database which we made during the current transaction.
Ans 18
View is a virtual table that does not e xists physically. Data in view is derived from original
table . create view v1 as select empno,ename from emp where deptno=10;
Ans 19
(a) SELECT NAME FROM GRADUATE WHERE DIV='I' ORDER BY NAME;
(b) SELECT NAME, STIPEND, SUBJECT, STIPEND*12 STIPEND_YEAR FROM GRADUATE;
(c) SELECT SUBJECT, COUNT(NAME) FROM GRADUATE GROUPBY
(SUBJECT) HAVING SUBJECT='PHYSICS' OR SUBJECT='COMP. Sc.';
(d) INSERT INTO GRADUATE VALUES(11,'KAJOL',300,'COMP. Sc.',75,1);
(e) (i) MIN(AVERAGE) 63
(ii) SUM(STIPEND) 800
(iii) AVG(STIPEND) 420
(iv) COUNT(DISTINCTSUBJECT) 4
(f) SELECT NAME, ADVISOR FROM GRADUATE, GUIDE WHERE
SUBJECT=MAINAREA; NAME ADVISOR
DIVYA RAJAN
SABINA RAJAN
KARAN VINOD
REKHA VINOD
JOHN VINOD
Ans 20
a) Select book_name, author_name , price from books where publisher=’First Publ’
b) Select book_name from books where type=’Text’
c) Select book_name, price from books Order by Price;
d) Update books set price=price+50 where publishers=’EPB’
e) Select a.book_id,a.book_name,b.quantity_issued from books a, issued b where
a.book_id=b.book_id
f) Insert into issued Values (‘F0003’,1);
g) (i) 5 (ii) 750 (iii)Fast Cook Lata Kappor (iv)My First c++ Brain &
Brooke
Ans 21
i. SELECT * FROM CLUB WHERE SPORTS=’SWIMMING’;
ii. SELECT COACHNAME,DATOFAPP FROM CLUB ORDER BY DATOFAPP DESC;
iii. SELECT COACHNAME, PAY, AGE, PAY *0.15 AS BONUS FROM CLUB ;
iv. SELECT COUNT(COACHNAME) FROM CLUB GROUP
BY SPORTS v.(a) 4
(b). 78000
(c)
Karate
Karate
Squash
Basketball
Swimming
Swimming
Squash
Karate
Swimming
Basketball
(d) 4 6 9 7
Ans 22
(i) SELECT * FROM TRANSACT WHERE TYPE = 'Deposit';
(ii) SELECT ANO,AMOUNT FROM TRANSACT WHERE DOT >= '2017-10-01' AND
DOT <= '2017- 10-31'; OR
SELECT ANO,AMOUNT FROM TRANSACT WHERE DOT BETWEEN '2017-10-01'
AND '2017-10- 31';
(iii) SELECT MAX(DOT) FROM TRANSACT WHERE ANO = 103;
(iv) SELECT ACCOUNT.ANO,ANAME,DOT FROM
ACCOUNT,TRANSACT WHERE
ACCOUNT.ANO=TRANSACT.ANO AND AMOUNT <=3000; OR
SELECT A.ANO,ANAME,DOT FROM ACCOUNT A,TRANSACT T WHERE
A.ANO=T.ANO AND AMOUNT <=3000;
(v) ANO ANAME
103 Ali Reza
105 Simran Kaur
(vi) DISTINCT ANO
101
102
103
(vii) ANO COUNT(*) MIN(AMOUNT)
101 2 2500
103 2 1000
(viii) SUM(AMOUN
COUN T) 5000
T(*) 2
(ix) Ano in Transact table
Ans 23. An index is a data structure maintained by database that helps it find records
within a table more quickly. Eg. To create index : create index id on emp(deptno);
CLASS XII
INFORMATICS PRACTICES
NEW (065)
Section A
Answer the following questions:
1 a) [70 10]
1 mark for correct answer
b) [1 2 3 3 2 1]
1 mark for correct answer
c) plt.hist(height)
f) A series is one dimensional object that can hold any data type such as integers,
floats, and strings. It has only one axis.
A DataFrame is two dimensional object that can hold different data types. Individual
columns of a dataframe can act as a separate series object.
a b1
first 1 NaN
second 5 NaN
1 mark for correct index and column name in both
cases 1 mark each for correct output (values) of
both cases
g) (i) df1+df2
(ii) dfa=df1.sort_values(‘Second’,ascending=False)
(iii) import pandas as pd
d={'First':[1,2,3,4],'Second':[5,6,7,8]}
df2=pd.DataFrame(d,index=['a','b','c','
d'])
(iv) df1[‘Third’].gt(50)
1 mark each for correct answer
Section B
3 a) Evolutionary model
1 mark for correct answer
b) Maintenance
1 mark for correct answer.
c) It is a set of methods and practices where solutions evolve through
collaboration between self organizing, cross functional teams.
1 mark for above definition or any suitable definition.
d) Features of sprints:
1. Sprints are periods of time when software development is actually done.
2. A sprint lasts from one week to one month to complete an item from the
backlog.
3. The goal of sprint is to create a saleable product.
4. Each sprint ends with sprint review.
½ mark each for above or any correct
feature. OR
Steps in waterfall model of software development:
Requirement specification, Analysis and System design, Implementation and
Unit
Testing, Integration and System Testing, Operation and maintenance.
2 marks for correct sequence of steps.
e) 1 mark for each correct
difference. OR
1 mark for each correct difference
f) 1 mark for correct definition of
VCS. 1 mark for commit / update
1 mark for push / pull requests.
g) 2 marks for correct use case diagram of taxi booking app.
2 marks for correct use case diagram of simple banking system.
Section C
4 a) init .py, settings.py, urls.py and wsgi.py
380000
428000
456000
500000
ii) Count(Distinct(City)
iii) Avg(sale)
4060000
iv) Area
East
North
Sout
h
Section D
5 a) 1 mark for correct definition
General Instructions:
SECTION A
Answer the following questions
1 (a) How would you create this identity matrix in python? 1
(a) np.eye(3)
(b) identity(3,2)
(c)np.array([1, 0, 0], [0, 1, 0], [0, 0, 1])
(d)All of these
(b) Consider the matrix of 5 observations each of 3 variables X0,X1,X2 whose 1
observed values are held in the three rows of the array X:
X = np.array([ [0.1, 0.3, 0.4, 0.8, 0.9], [3.2, 2.4, 2.4, 0.1, 5.5], [10., 8.2, 4.3, 2.6,
0.9] ])
Write the python statement to print the covariance of X and state that what does
the diagonal element of the resultant matrix depicts.
(c) Mr Ajay wants to plot a horizontal bar graph of the above given set of values with 1
programming language on x axis and its popularity on y axis with following code.
import matplotlib.pyplot as plt
x = ['Java', 'Python', 'PHP', 'JS', 'C#',
'C++'] popularity = [22.2, 17.6, 8.8, 8,
7.7, 6.7]
Statement
1 plt.xlabel("Popularity")
plt.ylabel("Languages")
plt.show()
Complete the code by writing statement1 to print the horizontal bar graph with
colour green
Or
Complete the Python program in blank line to draw a scatter graph taking a
random distribution in X and Y and plotted against each other in red colour.
import matplotlib.pyplot as
plt X = randn(200)
Y = randn(200)
plt.xlabel("X")
plt.ylabel("Y")
plt.show()
(d) Suppose you want to join train and test dataset (both are two numpy arrays train_set 2
and test_set) into a resulting array (resulting_set) to do data processing on it
simultaneously. This is as follows:
Original array:
[[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]]
Expected Output:
1 on the border and 0 inside in the
array [[ 1. 1. 1. 1. 1.]
[ 1. 0. 0. 0. 1.]
[ 1. 0. 0. 0. 1.]
[ 1. 0. 0. 0. 1.]
[ 1. 1. 1. 1. 1.]]
Or
Write a NumPy program to create a random 10x4 array and extract the first five
rows of
the array and store them into a variable
2 (a) All pandas data structures are -mutable but not always -mutable. 1
a) size,value
b) semantic,size
c) value,size
d) none of the Mentioned
(b) Suppose we make a dataframe as 1
df = pd.DataFrame(['ff', 'gg', 'hh', 'yy'], [24, 12, 48, 30], columns = ['Name', 'Age'])
Or
(i) Count the number of non-null value across the column for DataFrame dfC.
(ii) Find the most repeated value for a specific column ‘Weight’ of DataFrame dfC.
(iii) Find the median of hieght and weight column for all students using DataFrame
dfC
(h) Consider the following data frame of automobile 3
wheel- num-of-
index company body-style base cylinders price
0 bmw sedan 101.2 four 16925
1 bmw sedan 101.2 six 20970
2 honda sedan 96.5 four 12945
3 honda sedan 96.5 four 10345
4 toyota hatchback 95.7 four 5348
5 toyota hatchback 95.7 four 6338
(i) From the given data set print first and last five rows
(ii) Find the most expensive car company name
(iii) Sort all cars by price columns
SECTION B
3 (a) The Incremental Model is a result of combination of elements of which two 1
models?
2. Next, Bob edits the MyProj file foo.rb. Then, he does a commit and a push. What
does Git do when Bob issues these commands?
3. Next, Alice does a clone on MyProj. Then, Alice and Bob both edit foo.rb in
parallel. foo.rb has over 100 lines of code. Alice edits a couple lines at the top of
the file, and Bob edits a couple lines at the bottom of the file. Then, Bob does a
commit and a push. Finally, Alice does a commit and a push. What does Git do
when Alice issues the push command?
4. What Git commands should Alice issue next and what would the result of the
command be?
Or
Look at the following use case diagrams and write the actors and the situation
depicted by the Use Case diagram?
SECTION C
4 (a) Write the django command to create a project name school? 1
(b) What is 1
SAVEPOINT?
Or
What is Primary Key?
(c) What are two types of HTTP request? 1
(d) Write Mysql command that will be used to open an already existing database 1
“Contacts”
(e) method will return only one row from the resultset in the form of a 1
tuple containing record.
(f) (i) There is column salary in table employee. The following two statements are 3
giving different outputs. What may be the possible reasons?
Select count(*) from employee select count(salary) from employee
(ii) Mr. Sanghi created two tables with City as Primary Key in Table1 and Foreign
key in Table2 while inserting row in Table2 Mr Sanghi is not able to enter value in
the column City. What is the possible reason for it?
Or
Write a python code considering a database organization having a table employee
to update the salary for employee working in department 10 to 70000
SECTION D
5 (a) is a code injecting method used for attacking the database of a 1
system / website.
a) HTML injection
b) SQL Injection
c) Malicious code injection
d) XML Injection
(b) is a famous technological medium for the spread of malware, 1
facing
problems of spam, & phishing attacks.
(c) means authentication of any electronic records by a subscriber by 1
the means of an electronic method.
SECTION A
Answer the following questions
1 (a) Solution: (A) 1mark
Option B does not exist (it should be np.identity()and 2 parameters)
Option C is wrong, because the syntax is incorrect. So the answer is
option A
(b) print( np.cov(X) ) diagonal element represent variance 1
½ marks
for
eac
h correct
answer
(c) plt.barh(x_pos, popularity, color='green') 1 marks
or plt.scatter(X,Y, color='r')
(d) resulting_set = np.vstack([train_set, test_set]) 2 marks
Or
(g)1. When Bob issues the checkout command, Git creates a local copy of 4 marks
the MyProj repository and a working directory that contains the latest
snapshot of the project files. 1 marks for
2 The add commands “stages” the changes. The commit command each
updates Bob’s local repository to reflect the changes. The push
command updates the remote repository to reflect the changes in Bob’s
local repository.
3 When Alice issues the push command, Git rejects her push because
the remote branch has changed since the last time she pulled from it.
4. Alice should do a pull on the remote repository. That will update her
current branch in her local repository as well as her working directory.
The update will both download the changes in the remote repository and
merge them into her current branch. To then upload the merged
changes, she would need to do an add/commit/push.
Or
Use Case of Payroll management System calculating salary etc.Marks
are to
be distributed on basis of correct explnation
SECTION C
4 (a) django-admin startproject school 1mark
(b) SavePoint : Identiy a point in a transaction to which we can later roll 1mark
back Or
Primary Key : This refers to a set of one or more attributes that can
uniquely
identify tuples within the relation.
(c) GET and POST 1 mark
(d) Use contacts 1 mark
(e) fetchone()
(f) (i) contain null values 3 mark
1 mark for
each
(ii) 14 Mr Sanghi was trying to enter the name of City in Table2 which is
not present in Table1 i.e. Referential Integrity ensures that value must
exist in referred table.
(iii) alter is used to change the structure of object while update is used
to update the record in a table
(g) (i) UPDATE HOSPITAL SET CHARGE = CHARGE – 200 WHERE 3 marks 1
(DEPARTMENT = marks for
‘CARDIOLOGY’ AND SEX = ‘f’; each
(ii) INSERT INTO HOSPITAL VALUES
(11,‘Rakesh’,45,‘ENT’,{08/08/08}, 1200,
‘M’);
(iii) DELETE FROM HOSPITAL WHERE AGE > 60;
(h) (ii) SELECT * FROM GAMES WHERE PrizeMoney>7000; 4 marks
(ii) SELECT * FROM GAMES ORDER BY ScheduleDate; 1 marks
(iii) SELECT SUM(PrizeMoney),Number FROM GAMES GROUP BY for query
Number; ½
(iv) 2 marks for
(v) 19-Mar-2004 12-Dec-2003 each
Or output
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd=
"123"
,database="organization")
mycursor=mydb.cursor()
mycursor.execute("select * from
emp") data=mycursor.fetchall()
for x in data:
print(x)
mycursor.execute("update emp set sal={}
where empno={}".format(70000,10))
mydb.commit()
mycursor.execute("select * from
emp") data=mycursor.fetchall()
for x in data:
print(x)
SECTION D
5 (a) b 1 mark
(b) Email 1 mark
(c) Digital Signature
(d) Digital property refers to any information about you created by you that 2 marks
exists in digital form either online or on an storage device eb. Email id,
social
networking account etc
(e) under representation of girls, not girl friendly work culture unavailability 2marks
of
teaching material/aid lack of special needs teachers
(f) Describing of net neutrality, internet as echo 3 marks
chamber Or
Ewaste is electronic waste and process of ewaste disposal
KENDRIYA VIDYALAYA
SANGATHAN CLASS XII -
INFORMATICS PRACTICES (065)
SESSION ENDING EXAMINATION (SESSION 2019-20)
TIME ALLOWED : 3 HRS MM:70
General Instructions:
1. All the questions are compulsory.
Q. a What is the shape of the 1
1 following 1 2 3 4
567 8
f Q1: Underline the Error in the following code of data visualization and then rewrite the 2
rectified code
A=range(10,50,12
)
B=range(90,250,2
0)
matplotlib.pyplot.plot(a,b)
Q. a Name the function used to create frequency polygon 2
2
b What is the difference between pivot() and pivot_table() functions 2
WORKERS
W_ID FIRSTNAME LASTNAME ADDRESS CITY
102 Sam Tones 33 Elm St. Paris
105 Sarah Ackerman 440 U.S 110 New York
144 Manila Sengupta 24 Friends Street New Delhi
210 George Smith 83 First Street Howard
255 Mary Jones 842 VineAve. Lsantiville
300 Robert Samuel 9 Fifth Cross Washington
335 Henry Williams 12 Moore Street Boston
403 Ronny Lee 121 Harrison St. New York
451 Pat Thompson 11 Red Road Paris
DESIG
W_ID SALARY BENEFITS
DESIGNATION 102 75000
15000 Manager
105 85000 25000 Director
144 70000 15000 Manager
210 75000 12500 Manager
255 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
403 32000 7500 Salesman
451 28000 7500 Salesman
(i) To display W_ID Firstname, Address and city of all employees living in New York from
the table WORKERS.
(ii) To Display the content of WORKERS table in ascending order of LASTNAME.
(iii) To display the Firstname ,Lastname and Total Salary of all Clerks from the tables
WORKERS and DESIG , Where Total Salary is calculated as a Salary +Benefits.
(iv) To display the Minimum salary among Managers and Clerks from the table DESIG.
(v) SELECT
FIRSTNAME,SALARY
FROM
WORKERS,DESIG
WHERE DESIGNATION= ‘Manager’ AND WORKERS.W_ID =DESIGN.W_ID;
(vi) SELECT COUNT (DISTINCT DESIGNATION) FROM DESIG;
(vii) SELECT DESIGNATION,SUM(SALARY) FROM DESIG GROUP BY
DESIGNATION HAVING COUNT(*) < 3;
(viii)SELECT SUM(BENEFITS) FROM
WORKERS WHERE DESIGNATION
= ‘Salesman’;
Q.7 a What is Identity Theft ? 1
b What is plagiarism? How can you avoid plagiarism while referring to someone’s 2
else’s
creation?
c What are the common gender and disability issues faced while teaching / using 2
computers in classrooms?
d What is computer forensics? What important practices are followed in 2
computer
forensics?
e Describe the following terms 3
(i) Net Neutrality (ii) Crowd sourcing (iii) Smart Mobs
KENDRIYA VIDYALAYA
SANGATHAN CLASS XII -
INFORMATICS PRACTICES (065)
SESSION ENDING EXAM
MARKING SHEME (SESSION
2019-20)
TIME ALLOWED : 3 HRS MM:70
General Instructions:
2. All the questions are
compulsory. SECTION A
Q.1 a Size of matrix is 2 x 4 1
b Used to split an array both in horizontal as well as vertical by providing 1
axis=0,1
c (i) [[2030 40] (ii) [[ 80 70] 2
[60 70 80]] [120 110]]
d [1,2,3,3,2,1] 2
e Ndriya 2
f A=range(10,50,1 2
2)
B=range(90,160,2
0)
Matplotlib.pyplot.plot(a,b)
Error :The two sequences being plotted are not of same shape in the given
code
Q.2. a Use the function hist() with histtype=step 2
b Pivot() performs when there are multiple entries for a column values for same 2
values for index(row),it leads to error where as pivot_table() pivot the data by
aggregating
it,thus it can work with duplicate entries
c Quartiles Q1,Q2 and Q3 are three points that divides a distribution into 4 2
parts
In pandas it is generated with quartile() function
d (i) pv1=pd.pivot_table(dfN,index=[‘Stat
e’],
values=[‘Sales’],aggfunc=np.sum)
(iii) npv1=pd.pivot_table(dfN,index=[‘Name of
Employee’,’State’],values=[‘Sales’],aggfunc=np.sum)
(iv) pv1=pd.pivot_table(dfN,index=[‘State’],values=[‘Sal
es’], aggfunc=[np.mean,np.min,np.max])
Q.6 a 01 Marks for correct difference and 01 marks for correct example
b (i) SELECT W_ID, Firstname, Address, City
FROM workers
WHERE City = ‘New York’;
(ii) SELECT *
FROM
Workers
ORDER BY LASTNAME;
(iii) SELECT Firstname,Lastname, Salary + Benefits “Total
Salary” FROM Workers,Desig
WHERE Workers.W_ID =
Desig.W_ID AND Designation =
‘Clerk’;
(iv) SELECT Designation,
Min(salary) FROM Desig
GROUP BY Designation
HAVING Designation IN (‘Manager’,’Clerk’);
(v) Sam 75000
Manilla 70000
George 75000
(vi) 4
(vii) Director 85000
Salesman 60000
(viii) output will be 15000.
Q.7 a 01 Marks for correct definition 1
b 01 Marks for correct definition and 01 marks to explain how to avoid 2
plagiarism
c 01 Marks for gender issue 2
01 marks for correct disability issue
d 01 marks for definition of computer forensics 2
01 marks for explanation of important practices.
e 01 marks for each correct definition 3
KENDRIYA VIDYALAYA SANGATHAN
SAMPLE QUESTION PAPER
(2019-20) CLASS XII
Max Marks: 70
Time: 3 hrs
General Instructions:
All questions are compulsory
SECTION A
(c) Consider the following python code and write the output: 1
import pandas as pd
import numpy as np
data =
np.array(['a','b','c','d']) s =
pd.Series(data)
print(s)
(d) Write python code to transpose a dataframe D. 1
(f) Write python code to create a dataframe using following dictionary and sort the 2
dataframe in the descending order of age:
d=
{'Name':pd.Series(['Sachin','Dhoni','Virat','Rohit','Shikhar'])
, 'Age':pd.Series([26,25,25,24,31]),
'Score':pd.Series([87,67,89,55,47])}
(g) Consider the following dataframe 3
SECTION B
Q3 (a) Which software model enforces sequential software development? 1
(i) Waterfall
(ii) Spiral
(iii) Concurrent
(iv) None of the above
SECTION
C
Q4 (a) What is Django? 1
(b) Name two commands of TCL(Transaction Control Language) 1
(c) What is CSV File? 1
(d) What is the function of ALTER command? 1
(e) What is an SQL result set? 1
(f) Make difference between DELETE and DROP command. Explain with suitable 3
examples of
each.
(g) In a database there are two tables ‘LOAN’ and ‘BORROWER’ as shown below: 3
LOAN
Loan_Number Branch_name Amount
L-170 Downtown 3000
L-230 RedWood 4000
BORROWER
Customer_Name Loan_number
Jones L-170
Smith L-230
Hayes L-155
(iii) How many rows and columns will be there in the natural join of these
two tables?
(h) Write the SQL command for the following on the basis of given table. 4
(1) Display the names of the students who have grade ‘A’ in either Game1 or
Game2 or both.
(2) Display the number of students having game ‘Cricket’.
(3) Display the names of students who have same game for both Game1 and
Game2.
(4) Display the games taken by the students whose name starts with ‘A’.
SECTION
D
Q5 (a) What do you understand by ‘Intellectual Property Rights’? 1
(b) What is Spam? 1
(c) What is spoofing? 1
(d) What do you understand by e-waste management? Explain 2
(e) Explain Digital Rights Management. How can we protect our content? 2
(f) Write name of open source software: 3
1. An operating system
3. A programming language
KENDRIYA VIDYALAYA SANGATHAN
MARKING SCHEME
CLASS XII
Q1 (a) [ 20 40 60 80 100] 1
(1 mark for correct answer)
(b) print(np.cov(a,b)) 1
(1 mark for correct answer)
(c) plt.scatter(x,y 1
) plt.show()
(1/2 mark for each correct answer)
(d) [[ 1 2 3 4 5] 2
[ 6 7 8 9 10]
[11 12 13 14 15]]
(2mark for correct answer)
(e) import matplotlib.pyplot as plt 2
st =
['Tilak','Mahesh','Dinesh','Gopal']
marks = [50,60,30,45]
plt.barh(st.marks)
(2 mark for correct answer)
(f) DataFrame is a 2-dimensional labeled data structure with columns of potentially 2
different types. It is like a
spreadsheet or SQL table, or a dict of Series objects. It is generally the most
commonly used pandas object. Like
Series, DataFrame accepts many different kinds of input.
Example
import pandas as pd
d = {'one': [1., 2., 3., 4.],
'two': [4., 3., 2., 1.]}
pd.DataFrame(d)
(1 mark for definition and 1 mark for correct example)
(c) 0 a 1
1 b
2 c
3 d
dtype: object
(1 mark for correct answer)
(d) D.T 1
(e) Pivot_table is a generalization of pivot, which allows you to aggregate multiple 2
values with the same destination in the pivoted table.
(2 mark for correct answer)
(f) df= pd.DataFrame(d) 2
df=df.sort_values(by=['Age'],ascending=[Fa
lse])
(1 mark for creating and 2 marks for rest of the code)
(g) 1. df[['Score']].sum() 3
2. df[['Age']].mean()
3. df[['Score']].max()
(g) 1 mark for identification of actors , 2 marks for correct diagram and 1 mark for 4
correct
labels
Q4 (a) Django is an open source web application development framework. 1
(b) Commit, Rollback 1
(1 mark for correct answer)
(c) CSV (Comma Separated Values) is a simple file format used to store tabular data, 1
such as a spreadsheet or database.
(1 mark for correct answer)
(d) Alter command is used to change/modify the structure of database object like a table, index, 1
etc.
(1 mark for correct answer)
(e) An SQL result set is a set of rows from a database, as well as metadata about the 1
query such as the column names, and the types and sizes of each column.
(1 mark for correct answer)
(f) 1 mark for explanation and 2 marks for examples) 3
(g) (i) Degree: 3 3
Cardinality:
2
(ii) Loan_Number
(iii) Rows: 6
Columns:
5
(1 mark for each correct answer)
(h) 1. Select Name form GAME where Grade1 = ‘A’ or Grade2 = ‘A’; 4
2. Select Count(*) from GAME where Game1 = ‘Cricket or Game2 =’Cricket’;
3. Select Name from GAME where Game1 = Game 2;
4. Select Name, Game1, Game 2 from GAME where Name Like “A%”;
INFORMATICS PRACTICES
NEW (065)
Section A
Answer the following questions :
1 a) Find the output of following program. import numpy as 1
np d=np.array([10,20,30,40,50,60,70])
print(d[-4:])
b) Fill in the blank with appropriate numpy method to calculate and print the variance of an array. 1
import numpy as np
data=np.array([1,2,3,4,5,6]) print(np.
(data,ddof=0)
c) Mr. Sanjay wants to plot a bar graph for the given set of values of subject on x -axis and number 1
of students who opted for that subject on y-axis.
Complete the code to perform the following :
(i) To plot the bar graph in statement 1
(ii) To display the graph in statement 2
Mr. Harry wants to draw a line chart using a list of elements named LIST. Complete the code to
perform the following operations:
(i) To plot a line chart using the given LIST,
(ii) To give a y-axis label to the line chart named “Sample Numbers”.
e) Write a code to plot the speed of a passenger train as shown in the figure given below: 2
g) Write a NumPy program to create a 3x3 identity matrix, i.e. diagonal elements are 1, the rest are 0. 3
Replace all 0 to random number from 10 to 20
OR
Write a NumPy program to create a 3x3 identity matrix, i.e. non diagonal elements are 1, the rest are 0.
Replace all 0 to random number from 1 to 10
Answer the following questions
2 a) _ method in Pandas can be used to change the index of rows and columns of a Series 1
or Dataframe :
(i) rename()
(ii) reindex()
(iii) reframe()
(iv) none of the above
b) Hitesh wants to display the last four rows of the dataframedf and has written the following code 1
:
df.tail()
But last 5 rows are being displayed. Identify the error and rewrite the correct code so that last 4
rows get displayed.
OR
Write the command using Insert() function to add a new column in the last place(3 rd place) named
“Salary” from the list Sal=[10000,15000,20000] in an existing dataframe named EMP already having 2
columns.
c) Consider the following python code and write the output for statement S1 import pandas as pd 1
K=pd.series([2,4,6,8,10,12,14]) K.quantile([0.50,0.75]) S1
e) What is Pivoting? Name any two functions of Pandas which support pivoting. 2
f) Write a python code to create a dataframe with appropriate headings from the list given below : 2
['S101', 'Amy', 70], ['S102', 'Bandhi', 69], ['S104', 'Cathy', 75], ['S105',
'Gundaho', 82]
OR
Write a small python codeto create a dataframewith headings(a and b) from the list given below :
[[1,2],[3,4],[5,6],[7,8]]
g) Consider the following dataframe, and answer the questions given below: 3
import pandas as pd
df = pd.DataFrame({“Quarter1":[2000, 4000, 5000, 4400, 10000],
"Quarter2":[5800, 2500, 5400, 3000, 2900],
"Quarter3":[20000, 16000, 7000, 3600, 8200],
"Quarter4":[1400, 3700, 1700, 2000, 6000]})
(i) Write the code to find mean value from above dataframedf over the index and column axis. (Skip
NaN value)
(ii) Use sum() function to find the sum of all the values over the index axis.
(iii) Find the median of the dataframedf.
OR
Delhi 40 32 24.1
Bengaluru 31 25 36.2
Chennai 35 27 40.8
Mumbai 29 21 35.2
Kolkata 39 23 41.8
(i) Write command to compute sum of every column of the data frame.
(ii) Write command to compute mean of column Rainfall.
(iii) Write command to compute average maxTemp, Rainfall for first 5 rows
b) _ _ is the process of checking the developed software for its correctness and error free 1
working
(i) Specification
(ii) Design/Implementation
(iii) Validation/Testing
(iv) Evolution
OR
List any two differences betweenIncremental model and Spiral model in developing complex
software projects.
e) Write down any one situation where waterfall software process can be used. Also mention one 3
advantage and one disadvantage of waterfall software process.
OR
Write down any one situation where spiral delivery model can be used. Also mention one advantage
and one disadvantage of spiral delivery model.
f) Gunveen, Marshy and Aloha are three developers working on an exciting new app, and the launch 3
day is just a day away. Gunveen creates an unmanaged package and saves it Aloha’s folder. Marshy
also writes a new piece of code and saves it in Aloha’s folder. What could go wrong on the day of the
launch? Explain and also mention how version control can help teams in this scenario.
g) Draw a use case diagram and identify the actors for the situations (i) do (ii) as directed: 4
(i) A repair can be made by a master, a trainee or any other repair shop employee.
(ii) Consider an ATM system. Identify at least three different actors that interact with this system.
OR
(i) Look at the following use case diagrams and write the actors and the situation depicted by the use
case diagrams:
(ii) Look at the use case diagram shown below and explain the relationship depicted between A and B
Section C
4 a) Write the Django command to start a new app named ‘users’ in an existing 1
project?
f) Shewani has recently started working in MySQL. Help her in understanding the difference between 3
the following :
(i) Where and having clause
(ii) Count(column_name) and count(*)
Table: CUSTOMER_DETAILS
+ -+ + -+ + + +
| Cust_ID | Cust_Name | Acct_Type | Accumlt_Amt | DOJ | Gender |
+ -+ + -+ + + +
| CNR_001 | Manoj | Saving | 101250 | 1992-02-19 | M |
| CNR_002 | Rahul | Current | 132250 | 1998-01-11 | M |
| CNR_004 | Steve | Saving | 18200 | 1998-02-21 | M |
| CNR_005 | Manpreet | Current | NULL | 1994-02-19 | M |
+ -+ + -+ + + +
h) Write commands in SQL for (i) to (iv) and output for (v) and (vi). 4
Table : Store
+---------+----------------+----------------+--------+---------+------------+---------+
| StoreId | Name | Location | City | NoOfEmp | DateOpen |SalesAmt |
+---------+----------------+----------------+--------+---------+------------+----------+
| S101 | Planet Fashion | Bandra | Mumbai | 7 | 2015-10-16 | 40000 |
| S102 | Vogue | Karol Bagh | Delhi | 8 | 2015-07-14| 120000 |
| S103 | Trends | Powai | Mumbai | 10 | 2015-06-24 | 30000 |
| S104 | SuperFashion | Thane | Mumbai | 11 | 2015-02-06 | 45000 |
| S105 | Annabelle | South Extn. | Delhi | 8 | 2015-04-09 | 60000|
| S106 | Rage | Defence Colony | Delhi | 5 | 2015-03-01 | 20000 |
+---------+----------------+----------------+--------+---------+------------+----------+
(i) To display names of stores along with SalesAmount of those stores that have ‘fashion’ anywhere in
their store names.
(ii) To display Stores names, Location and DateOfOpen of stores that were opened before 1st March,
2015.
(iii) To display name and location of those store which have either ‘u’ as second character in their name.
(iv) To display the City and the number of stores located in that City, only if number of stores is more
than 2.
(v) Select Min(DateOpen) from Store;
(vi) Select Count(Storeid), Noofemp From Store Group By Noofemp Having Max(Salesamt)<60000;
OR
(i) In a school, a database named “school” is created in mysql whose password is “cbse”. Smith is
trying to add a new record of a student havingdetails(3,’Michelle’,’Agartala’) in a“student”table.
(ii) Write the code in python to read the contents of “number.csv” file
consisting of data from a mysql table and print the data of the table on the screen in tabular form of
the table.
Section D
5 a) Which of the following is not an intellectual property? 1
(i) A poem written by a poet
(ii) An original painting made by a painter
(iii) Trademark of a Company
(iv) A remixed song
b) Jhilmalini has stolen a credit card. She used that credit card to purchase a laptop. What type of offence 1
has she committed?
c) Name the primary law in India dealing with cybercrime and electronic commerce. 1
d) Sutapa received an email from her bank stating that there is a problem with her account. The email 2
provides instructions and a link, by clicking on which she can logon to her account and fix the
problem. Help Sutapa by telling her the precautions she should take when she receives these type of
emails.
e) Explain any two ways in which technology can help students with disabilities. 2
f) Explain the role of online social media campaigns, crowdsourcing and smart mobs in society. 3
OR
Ms Samtha has many electronics gadgets which are not usable due to outdated hardware and
software. Help her to find any three best ways to dispose the used electronic gadgets.
Page
109
CLASS XII
INFORMATICS PRACTICES -
New (065)
Marking Scheme - SQP (2019-20)
Section A
OR
(i) PLINE.plot(LIST)
(ii) PLINE.ylabel(“Sample Numbers”)
d) Ans [10 12 16 20] (1 mark for correct
output)
Page
110
OR 1 mark for creation of
import numpy as np matrix
Z = np.arange(9).reshape(3,3) 1 mark for
print (Z) x=np.where((Z%2)==0) identification of even
for i in x: number
Z[x]=np.random.randint(low=10,high=20) print(Z) 1 mark for changing
value of 0 to random
number
EMP.insert(loc=3,column=”Salary”,value=Sal)
c) Ans 0.50 8.0 (1 mark for each
0.75 11.0 correct line of
output)
d) Ans # Drop rows with label 0 df ( 1 mark for giving
= df.drop(0) complete and
print(df ) correct code)
e) An Pivoting means to use unique values from specified (1 mark for correct
index/columns to form apex of the resulting dataframe. definition and ½ mark
s
Pivot() and pivot_table() methods for each correct
example)
import pandas as pd
df = pd.DataFrame([[1, 2], [3, 4]], columns = ['a','b'])
df2 = pd.DataFrame([[5, 6], [7, 8]], columns = ['a','b'])
df = df.append(df2)
g)Ans (i) print(df.mean(axis = 1, skipna = True)) 3 marks
print(df.mean(axis = 0, skipna = True))
(ii) print(df.sum(axis = 1, skipna = True)) (1 mark for each
(iii) print(df.median()) correct code )
Page
111
OR
(i) df1.sum()
(ii) df1[‘Rainfall’].mean()
(iii) df1.loc[:11, ‘maxtemp’:’Rainfall’].mean( )
Section B
Q3 a)Ans Concurrent Process model (1 mark for correct
answer)
c)Ans Improved code quality: As second partner reviews the code (1 mark for correct
simultaneously, it reduces the chances of mistake. answer)
d)Ans → The ScrumMaster is the servant leader to the Product Owner, 2 marks
Development Team and Organization with no hierarchical authority (1 mark for correct
over the team but rather more of a facilitator, the ScrumMaster answer and 1 mark for
ensures that the team adheres to Scrum theory, practices, and rules. correct
→The ScrumMaster protects the team by doing anything possible to justification)
help the team perform at the highest level.
OR
Page
112
e)Ans Situations to use/apply waterfall model 3 marks
i) When project is small
(1 mark for any correct
ii) When problem is static.
area of use 1 mark for
iii) Clear and fixed requirements. Stable problem definition.
correct advantage and
Technology is static.
1 mark for correct
disadvantage)
Advantage :
Simple and easy to understand
Disadvantage :
No working software till the last phase
OR
f)Ans →The team members are not working in a systematic way and they are 3 marks
not saving the versions of their work. Changes made in one part of the
software can be incompatible with those made by another developer (1 mark for identifying
working at the same time. the problem, 1 mark for
→Version control exists to solve these problems, and it’s within easy explaining version
reach for every developer. Version control helps teams solve these control and 1 mark for
kinds of problems, tracking every individual change by each its advantages)
contributor and helping prevent concurrent work from conflicting.
→Further, in all software development, any change can introduce new
bugs on its own and new software can't be trusted until it's tested. So
testing and development proceed together until a new version is ready.
g)Ans 4 marks
Page
113
system of interest. For an ATM, this includes:
• Bank Customer
• ATM Maintainer
• Central Bank Computer
OR
A teacher is conducting an interview with a student. In the course of (1½ mark for each
that, the teacher always has to grade the student. correct explanation
Father and son cook dinner. In the course of that, one of them always and 1 mark
has to load the dishwasher. explaining the
1. B can execute the same use cases as A. relationship)
2. B inherits all of A's associations.
Section C
b)Ans Commit is used to save all the DML transactions, and once saved they (1 mark for correct
cannot be rolled back. answer)
OR
e)Ans verify whether the python application is connected to mysql database. (1 mark for correct
answer)
f)Ans (i) Where clause is used to show data set for a table based on a condition 3 marks
and having clause is used to put condition on the result set that comes
after using Groupby clause. ( 1 mark for each
correct difference)
(ii) COUNT(*) returns the number of items in a group, including
NULL values and duplicates. COUNT(expression) evaluates
expression for each row in a group and returns the number of non null
values.
Candidate Key – A Candidate Key can be any column or a
combination of columns that can qualify as unique key in database.
There can be multiple Candidate Keys in one table. Each Candidate
Key can qualify as Primary Key.
Primary Key – A Primary Key is a column or a combination of
columns that uniquely identify a record. Only one Candidate Key can
be Primary Key.
A table can have multiple Candidate Keys that are unique as single
column or combined multiple columns to the table. They are all
candidates for Primary Key.
g)Ans 3 marks
Page
114
(i) The degree is 6 and cardinality is 5. (½ mark for correct
degree and ½ mark
(ii)
for cardinality)
+ +
| max(DOJ) | (1 mark for correct
+------------+ output)
| 1998-02-21 |
+ +
(1 mark for correct
query)
(iii)Delete from Customer_Details where Accumlt_Amt is NULL;
Page
115
Section D
Q5 a)Ans A remixed song is not an intellectual property (1 mark for correct
answer)
OR
(1 mark for each
1. Give Your Electronic Waste to a Certified E-Waste Recycler correct ways of
2. Donating Your Outdated Technology disposing e waste)
3. Give Back to Your Electronic Companies and Drop Off
Points.
Page
116