Practical No – 01
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
# Programme to find Simple Interest
p = float(input('Enter principle'))
r = float(input('Enter rate'))
t = float(input('Enter time'))
i=p*r*t/100
print("Interest=",i)
Output:
Enter principle22000
Enter rate15
Enter time8
Interest= 26400.0
Practical No – 02
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
# Program to check whether a number is divisible by 2 or 3 using
nested if
num=float(input('Enter a number'))
if num%2==0:
if num%3==0:
print ("Divisible by 3 and 2")
else:
print ("divisible by 2 not divisible by 3")
else:
if num%3==0:
print ("divisible by 3 not divisible by 2")
else:
print ("not Divisible by 2 not divisible by 3")
Output:
Enter a number144
Divisible by 3 and 2
Practical No – 03
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#. Menu based program to find sum, subtraction, #multiplication
and division of values.
print("1. Sum of two numbers")
print("2. Subtaction of two numbers")
print("3. Multiplication of two numbers")
print("4. Division of two numbers")
choice=int(input('Enter your choice'))
if choice==1 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a+b
print("Sum=",c)
elif choice==2 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a-b
print("Subtraction=",c)
elif choice==3 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a*b
print("Multiplication=",c)
elif choice==4 :
a=int(input('Enter first number'))
b=int(input('Enter second number'))
c=a/b
print("Division=",c)
else :
print("Wrong choice")
Output:
1. Sum of two numbers
2. Subtaction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
Enter your choice3
Enter first number567
Enter second number7865
Multiplication= 4459455
Practical No – 04
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to print result depending upon the percentage.
a=int(input('Enter your percentage'))
eligible= a>=33
compartment = a>=20 and a<33
fail=a<20
if eligible :
print("Pass");
elif compartment :
print("compartment");
elif fail:
print("Fail");
Output:
Enter your percentage578
Pass
Practical No – 05
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
# Program to find factorial of a number.
n=eval(input("Enter a number="))
i=1
f=1
while i<=n:
f=f*i #1*2*3*4*5
i=i+1
print("Factorial of",n,"=",f)
Output:
Enter a number=57
Factorial of 57 =
405269195048772167556806019054323221349803847962266021451844812
80000000000000
Practical No – 06
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to sort values in a list.
aList=eval(input(“Enter list:”))
print("Original List",aList)
n=len(aList)
for i in range(n-1):
for j in range(0,n-i-1):
if aList[j]>aList[j+1]:
aList[j],aList[j+1]=aList[j+1],aList[j]
print("Sorted List",aList)
Output:
Enter list:[34,65,23,67,54]
Original List [34, 65, 23, 67, 54]
Sorted List [23, 34, 54, 65, 67]
Practical No – 07
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to sort a sequence using insertion sort.
aList =[15,6,13,22,3,52,2]
print("Original list is =",aList)
for i in range(1,len(aList)):
key=aList[i]
j=i-1
while j>=0 and key<aList[j]:
aList[j+1]=aList[j]
j=j-1
else:
aList[j+1]=key
print("list after sorting:",aList)
Output:
Original list is = [15, 6, 13, 22, 3, 52, 2]
list after sorting: [2, 3, 6, 13, 15, 22, 52]
Practical No – 08
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to find largest among two numbers using function a user
#defined
def largest():
a=int(input("Enter first number="))
b=int(input("Enter second number="))
if a>b :
print ("Largest value=%d"%a)
else:
print ("Largest value=%d"%b)
return
largest()
Output:
Enter first number=67
Enter second number=76
Largest value=76
Practical No – 09
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to find simple interest using a user defined function with
parameters #and with return value.
def interest(p1,r1,t1 ):
i=p*r*t/100
return(i)
p=int(input("Enter principle="))
r=int(input("Enter rate="))
t=int(input("Enter time="))
in1=interest(p,r,t)
print("Interest=",in1)
Output:
Enter principle=76890
Enter rate=14
Enter time=9
Interest= 96881.4
Practical No – 10
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to pass a list as function argument #and modify it.
def changeme( mylist,n ):
print ("inside the function before change ", mylist)
mylist[0]=n
print ("inside the function after change ", mylist)
return
list1 = eval(input("Enter list:"))
n=input("Enter value to mdify:")
ind=int(input("Enter index no which is to be modify:"))
print ("outside function before calling function", list1)
changeme( list1,n )
print ("outside function after calling function", list1)
Output:
Enter list:[78,95,45,67,65]
Enter value to mdify:63
Enter index no which is to be modify:3
outside function before calling function [78, 95, 45, 67, 65]
inside the function before change [78, 95, 45, 67, 65]
inside the function after change ['63', 95, 45, 67, 65]
outside function after calling function ['63', 95, 45, 67, 65]
Practical No – 11
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to use default arguments in a function.
def printinfo( name, age = 35 ): #default argument
print ("Name: ", name)
print ("Age ", age)
return
name=input("Enter name:")
age=int(input("Enter age:"))
printinfo(name)
printinfo(name,age)
Output:
Enter name:'Ajay'
Enter age:56
Name: 'Ajay'
Age 35
Name: 'Ajay'
Age 56
Practical No – 12
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
# Program to display the size of a file after removing EOL
# characters, leading and trailing white spaces and blank lines.
Myfile =open(r’E:\[Link],”r”)
Str1=” ” #initially storing a space (any non-None value)
size=0
tsize =0
while str1:
str1=[Link]()
tsize=tsize+len(Str1)
size=size+len([Link]())
print(“Size of file after removing all EOL characters & blank lines:”,size)
print(“The total size of the file:”,tsize )
[Link]()
Output:
Size of the file after removing all EOL characters & blank lines: 360
The total size of the file: 387
Practical No – 12
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program to roll numbers, names and marks of the
#students of a class(get from user) and sort these details in
# a file called “[Link]”.
count=int(input(“How many students are there in the class ?”))
fileout=open(“[Link]”,”w”)
for i in range(count):
print(“Enter details for students”,(i+1),”below”)
rollno=int(input(“Roll no.:”))
name=input(“Name:”)
marks=float(input(“Marks:”))
rec=str(rollno)+”,”+name+”,”+str(marks)+’\n’
[Link](rec)
[Link]()
Output:
How many students are there in the class: 3
Enter details for student 1 below:
Rollno: 12
Name: Hazel
Marks: 67.75
Enter details for student 2 below:
Rollno: 15
Name: Jiya
Marks: 78.5
Enter details for student 3 below:
Rollno: 16
Name: Noor
Marks: 68.9
Practical No – 13
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Write a program to read a text file line by line and display each
#word separated by a ‘#’.
Myfile=open(“[Link]”,”r”)
Line=” ” #initially storing a space (any non-None value)
While line:
Line=[Link]() #one line read from file
#printing the line word by word using split()
for word in [Link]():
print(word,end=’#’)
print()
#close the file
[Link]()
Output:
Letter#’a’#is#a#wonderful#letter.#
It#is#impossible#to#think#of#a#sentence#without#it.#
Practical No – 14
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
# Ptogram to create a CSV file to store student data (Rollno., Name,
# Marks), obtain data from user and write 3 records into the file.
import csv
fh=open(“[Link]”,”w”)
[Link](*‘Rollno’,’Name’,’Marks’+)
for i in range(5):
print(“Student record”,(i+1))
rollno=int(input(“Enter roll no:”))
name=input(“Enter name:”)
marks=float(input(“Enter marks:”))
sturec=[rollno,name,marks]
[Link](sturec)
[Link]() #close file
Output:
Student record 1
Enter rollno:11
Enter name: Nistha
Enter marks: 79
Student record 2
Enter rollno: 12
Enter name: Rudy
Enter marks: 89
Student record 3
Enter rollno: 13
Enter name: Rustom
Enter marks: 93
Practical No – 15
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Program for deletion of an element from a sorted #linear list
def Bsearch(AR,ITEM):
beg=0
last=len(AR)-1
while (beg<=last):
mid=(beg+last)/2
if (ITEM==AR[mid]):
return mid
elif (ITEM>AR[mid]):
beg=mid+1
else:
last=mid-1
else:
return False
#_main_
myList=[10,20,30,40,50,60,70]
print("The list in sorted order is")
print(myList)
ITEM=int(input("Enter element to be deleted:"))
position=Bsearch(myList,ITEM)
if position:
del myList[position]
print("The list after deleting",ITEM,"is")
print(myList)
else:
print("SORRY!No such element in the list")
Output:
The list in sorted order is
[10, 20, 30, 40, 50, 60, 70]
Enter element to be deleted : 40
The list after deleting 40 is
[10, 20, 30, 50, 60, 70]
Practical No – 16
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
#Python program to implement stack operations.
############### STACK IMPLEMENTATION ###############
”””
Stack : implemented as a list
top : integer having position of topmost element in Stack
”””
Def isEmpty(stk) :
if stk==[] :
return True
else :
return False
def Push(stk,item) :
[Link](item)
top=len(stk)-1
def Pop(stk) :
if isEmpty(stk) :
return”Underflow”
else :
item=[Link]()
if len(stk)==0 :
top=len(stk)-1
return item
def Peek(stk) :
if isEmpty(stk) :
return”Underflow”
else:
top=len(stk)-1
return stk[top]
def Display(stk) :
if isEmpty(stk):
print(“Stack empty”)
else:
top=len(stk)-1
print(stk*top+,”<-top”)
for a in range(top-1,-1,-1):
print(stk[a])
#___main___
Stack=[]
Top=None
While True :
print(“STACK OPERATIONS”)
print(“[Link]”)
print(“[Link]”)
print(“[Link]”)
print(“[Link] stack”)
ch=int(input(“Enter your choice(1-5) :”)
if ch==1 :
item=int(input(“Enter item:”))
Push(Stack,item)
elif ch ==2:
item=Pop(Stack)
if item==”Underflow”:
print(“Underflow! Stack is empty!”)
else:
print(“Popped item is”,item)
elif ch==3 :
item=Peek(Stack)
if item ==”Underflow” :
print(“Underflow! Stack is empty!”)
else:
print(“Topmost item is” , item)
elif ch == 4:
Display(Stack)
elif ch==5 :
break
else:
print(“Invalid choice”)
Output:
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display
5. Exit
Enter your choice (1-5) : 1
Enter item : 6
---------------------------
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display stack
5. Exit
Enter your choice (1-5) : 1
Enter item : 8
--------------------------
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display stack
5. Exit
Enter your choice (1-5) : 1
Enter item : 2
--------------------------
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display stack
5. Exit
Enter your choice (1-5) : 1
Enter item : 4
--------------------------
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display stack
5. Exit
Enter your choice (1-5) : 4
4<-top
------------------------
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display stack
5. Exit
Enter your choice (1-5) : 3
Enter item : 4
-------------------------
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display stack
5. Exit
Enter your choice (1-5) : 4
4<-top
------------------------
STACK OPERATIONS
1. Push
2. Pop
3. Peek
4. Display stack
5. Exit
Enter your choice (1-5) : 5
Practical No – 17
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective-SQL QUERIES
SQL 1
(i) Display the Mobile company, Mobile name & price in descending
order of their manufacturing date.
Ans. SELECT M_Compnay, M_Name, M_Price FROM MobileMaster
ORDER BY M_Mf_Date DESC;
(ii) List the details of mobile whose name starts with “S”.
Ans. SELECT * FROM MobileMaster
WHERE M_Name LIKE “S%‟;
(iii) Display the Mobile supplier & quantity of all mobiles except
“MB003‟.
[Link] M_Supplier, M_Qty FROM MobileStock
WHERE M_Id <>”MB003”;
(iv) To display the name of mobile company having price between 3000 &
5000.
Ans. SELECT M_Company FROM MobileMaster
WHERE M_Price BETWEEN 3000 AND 5000;
**Find Output of following queries
(v) SELECT M_Id, SUM(M_Qty) FROM MobileStock GROUP BY M_Id;
MB004 450
MB003 400
MB003 300
MB003 200
(vi) SELECT MAX(M_Mf_Date), MIN(M_Mf_Date) FROM MobileMaster;
2017-11-20 2010-08-21
(vii) SELECT M1.M_Id, M1.M_Name, M2.M_Qty, M2.M_Supplier
FROM MobileMaster M1, MobileStock M2 WHERE M1.M_Id=M2.M_Id
AND M2.M_Qty>=300;
MB004 Unite3 450 New_Vision
Classic Mobile
MB001 Galaxy 300
Store
(viii) SELECT AVG(M_Price) FROM MobileMaster;
5450
Practical No – 18
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective-SQL QUERIES
SQL 2
i. Display the Trainer Name, City & Salary in descending order of
theirHiredate.
Ans. SELECT TNAME, CITY, SALARY FROM TRAINER
ORDER BY HIREDATE;
ii. To display the TNAME and CITY of Trainer who joined the Institute in
the month of December 2001.
Ans. SELECT TNAME, CITY FROM TRAINER
WHERE HIREDATE BETWEEN „2001-12-01‟
AND „2001-12-31‟;
iii. To display TNAME, HIREDATE, CNAME, STARTDATE from
tables TRAINER and COURSE of all those courses whose FEES is less than
or equal to 10000.
Ans. SELECT TNAME,HIREDATE,CNAME,STARTDATE FROM TRAINER, COURSE
WHERE [Link]=[Link] AND FEES<=10000;
iv. To display number of Trainers from each city.
Ans. SELECT CITY, COUNT(*) FROM TRAINER
GROUP BY CITY;
**Find Output of following queries
v. SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT IN(‘DELHI’,
‘MUMBAI’);
Practical No – 19
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
SQL 3
i) To display details of those Faculties whose salary is greater than 12000.
Ans: Select * from faculty
where salary > 12000;
ii) To display the details of courses whose fees is in the range of 15000 to
50000 (both values included).
Ans: Select * from Courses
where fees between 15000 and 50000;
iii ) To increase the fees of all courses by 500 of “System Design” Course.
Ans: Update courses set fees = fees + 500
where Cname = “System Design”;
(iv) To display details of those courses which are taught by ‘Sulekha’ in
descending order of courses.
Ans: Select * from faculty,courses
where faculty.f_id = course.f_id and [Link] = 'Sulekha'
order by cname desc;
SQL 4
i. To display all the details of those watches whose name ends with ‘Time’
Ans select * from watches
where watch_name like „%Time‟;
ii. To display watch’s name and price of those watches which have price
range in between 5000-15000.
Ans. select watch_name, price from watches
where price between 5000 and 15000;
iii. To display total quantity in store of Unisex type watches.
Ans. select sum(qty_store) from watches where type like ‟Unisex‟;
iv. To display watch name and their quantity sold in first quarter.
Ans. select watch_name,qty_sold from watches w,sale s
where [Link]=[Link] and quarter=1;
Practical No – 20
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :
Date : Chapter :
Remarks : Teacher’s sign :
Objective and Solution
SQL 5
(i) To display the records from table student in alphabetical order as per
the name of the student.
Ans. Select * from student
order by name;
(ii ) To display Class, Dob and City whose marks is between 450 and 551.
Ans. Select class, dob, city from student
where marks between 450 and 551;
(iii) To display Name, Class and total number of students who have
secured more than 450 marks, class wise
Ans. Select name,class, count(*) from student
group by class
having marks> 450;
(iv) To increase marks of all students by 20 whose class is “XII
Ans. Update student
set marks=marks+20
where class=‟XII‟;