GURU HARKRISHAN PUBLIC SCHOOL
Session:- 2021-22
Computer science Practical File
Made by :- Sanchit Vohra
Class :- 12 th B
Roll no:- 42
ACKNOWLEDGMENT
In the accomplishment of these prcaticals successfully,
many people have bestowed upon me their blessings
and heart
pledged support, this time I am utilizing to thank all the
people who
have been concerned with these practical.
Primarily I would thank God, for being able to complete
these
practicals with success. Then I would like to thank my
Computer
Science teacher Mr. Shukdev Nayyar, whose valuable
guidance has
been the ones that helped me patch this project and
make it full
proof success; his suggestions and his instructions has
served as the
major contributor towards the completion of these
practicals.
Then I would like to thank my parents and friends who
have helped
me with their valuable suggestions and guidance, which
proved to be helpful in various phases of the completion
of these practicals
Computer Science Practical File Work
Name:- Sanchit Vohra
Class :-12 th B
#Python programs
Que 1. Program to find minimum value in a list.
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
s=a+b
p=a*b
if(a>b):
d=a-b
else:
d=b-a
print("Sum = ",s)
print("Product = ",p)
print("Difference = ",d)
Output #1
Que 2. Write a python script to take input for 3
numbers, check and print the largest number?
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
m=a
else:
if(b>c):
m=b
else:
m=c
print("Max no = ",m)
Output #2
Que 3. Write a python script to take input for 2
numbers and an operator (+ , – , * , / ). Based on
the operator calculate and print the result?
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
op=input("Enter the operator (+,-,,/) ")
if(op=="+"):
c=a+b
print("Sum = ",c)
elif(op==""):
c=a*b
print("Product = ",c)
elif(op=="-"):
if(a>b):
c=a-b
else:
c=b-a
print("Difference = ",c)
elif(op=="/"):
c=a/b
print("Division = ",c)
else:
print("Invalid operator")
Output #3
Que 4. Write a python script to Display Fibonacci
Sequence Using Recursion?
#Python program to display the Fibonacci sequence
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
nterms = 10
#check if the number of terms is valid
if (nterms <= 0):
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
Output #4
Que 5. Write a python script to take input for a
number and print its factorial using recursion?
#Factorial of a number using recursion
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
#for fixed number
num = 7
#using user input
num=int(input("Enter any no "))
#check if the number is negative
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of", num, "is", recur_factorial(num))
Output #5
Que 6. Write a python script to take input for a
number check if the entered number is
Armstrong or not.
n=int(input("Enter the number to check : "))
n1=n
s=0
while(n>0):
d=n%10;
s=s + (d *d * d)
n=int(n/10)
if s==n1:
print("Armstrong Number")
else:
print("Not an Armstrong Number")
Output #6
Que 7. Write a python script to take input for a
number and print its table?
n=int(input("Enter any no "))
i=1
while(i<=10):
t=n*i
print(n," * ",i," = ",t)
i=i+1
Output #7
Que 8. Write a python program to maintain book
details like book code, book title and price using
stacks data structures? (implement push(), pop()
and traverse() functions)
"""
push
pop
traverse
"""
book=[]
def push():
bcode=input("Enter bcode ")
btitle=input("Enter btitle ")
price=input("Enter price ")
bk=(bcode,btitle,price)
book.append(bk)
def pop():
if(book==[]):
print("Underflow / Book Stack in empty")
else:
bcode,btitle,price=book.pop()
print("poped element is ")
print("bcode ",bcode," btitle ",btitle," price ",price)
def traverse():
if not (book==[]):
n=len(book)
for i in range(n-1,-1,-1):
print(book[i])
else:
print("Empty , No book to display")
while True:
print("1. Push")
print("2. Pop")
print("3. Traversal")
print("4. Exit")
ch=int(input("Enter your choice "))
if(ch==1):
push()
elif(ch==2):
pop()
elif(ch==3):
traverse()
elif(ch==4):
print("End")
break
else:
print("Invalid choice")
Output #8
Que 9. Write a python script to take input for
name and age of a person check and print
whether the person can vote or not?
name=input("Enter name ")
age=int(input("Enter age "))
if(age>=18):
print("you can vote")
else:
print("you cannot vote")
Output #9
Que 10. 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 #10
My sql tables
SQL Table 1:-
Queries:-
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 fac.fname = 'Sulekha'
order by cname desc;
**Find output of following
v) Select COUNT(DISTINCT F_ID) from COURSES;
Ans: 4
vi) Select MIN(Salary) from FACULTY,COURSES where
COURSES.F_ID = FACULTY.F_ID;
Ans: 6000
vii) Select sum(fees) from COURSES where F_ID = 102;
Ans: 60000
vii) Select avg(fees) from COURSES;
Ans: 17500
My SQL Table 2:-
Queries:-
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 w.watchid=s.watchid and quarter=1;
v. select max(price), min(qty_store) from watches;
Ans. 25000 100
vi. select quarter, sum(qty_sold) from sale group by quarter;
1 15
2 30
3 45
4 15
vii. select watch_name,price,type from watches w, sales where
w.watchid!=s.watchid;
HighFashion 7000 Unisex
viii. select watch_name, qty_store, sum(qty_sold), qty_store-
sum(qty_sold) “Stock” from watches w, sale s where
w.watchid=s.watchid group by s.watchid;
HighTime 100 25 75
LifeTime 150 40 110
Wave 200 30 170
Golden Time 100 10 90
My SQL Table 3:-
Queries:-
(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’;
**Find output of the following queries.
(v) SELECT COUNT(*), City FROM STUDENT GROUP BY CITY HAVING
COUNT(*)>1;
2 Mumbai
2 Delhi
2 Moscow
(vi ) SELECT MAX(DOB),MIN(DOB) FROM STUDENT;
08-12-1995 07-05-1993
(iii) SELECT NAME,GENDER FROM STUDENT WHERE CITY=’Delhi’;
Sanal F
Store M
My SQL Table 4:-
Queries:-
(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‟.
Ans.SELECT 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
My SQL Table 5:-
Queries:-
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 TRAINER.TID=COURSE.TID 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’);
Ans.
103 DEEPTI
106 MANIPRABHA
vi. SELECT DISTINCT TID FROM COURSE;
Ans.
101
103
102
104
105
vii. SELECT TID, COUNT(*), MIN(FEES) FROM COURSE GROUP BY TID
HAVING COUNT(*)>1;
Ans.
101 2 12000