Dedraj sewali devi todi
d.a.v [k.v.b] school
Computer science
Practical file on python programs and mysql
Submitted to :_______________
Submitted by: _______________
DATE :_______________
CERTIFICATE
THIS IS TO CERTIFY THAT OF CLASS XII HAS
SUCCESSFULLY COMPLETED HER COMPUTER PROJECT ON THE TOPIC "PYTHON
PROGRAMS ANS SQL QUERIES" AS PRESCRIBED BY
Sir, DURING THE ACADEMIC YEAR 2020-2021 AS PER THE GUIDELINES
ISSUES BY CENTRAL BOARD OF SECONDARY EDUCATION - CBSE
________________
Principal
------------------------------ ------------------------
Internal Examiner External Examiner
ACKNOWLEDGEMENT
I would like to take this opportunity to thank my computer teacher MR.ASHISH Sir , for
guiding me in my project, for providing valuable suggestions, for her ongoing support during
the project, from initial advice, and provision of contacts in the first stages through ongoing
advice and encouragement, which led to the final report of this computer project.
I am also grateful to our respected principal MR. RAMESH MISHRA and Vice principal Mrs.
MILLI SHARMA for their support.
A special acknowledgement goes to my colleagues who helped me in completing the project by
exchanging interesting ideas and sharing their experience.
I would like to express my gratitude towards my parents for their kind co-operation and
encouragement which help me in the completion of this project.
I have taken efforts in this project. However, it would not have been possible without the kind
support and help of many individuals. I would like to extend my sincere thanks to all of them.
1. 20 python programs……
1. Write a Python program which accepts the radius of a circle from the user and
compute the area.
from math import pi
r = float(input ("Input the radius of the circle:”))
print("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2))
Input the radius of the circle : 1.1
The area of the circle with radius 1.1 is: 3.8013271108436504
2. write a python program to print the sum of digits of a number.
n=int(input("Enter a number:"))
tot=0
while(n>0):
dig=n%10
tot=tot+dig
n=n//10
print("The total sum of digits is:",tot)
output:
Enter a number:1892
The total sum of digits is: 20
3. Write a python program to find the factorial a number input by the user.
num = int(input("Enter a number: "))
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
OUTPUT:
num = 7
The factorial of 7 is 5040
4. Write a program to print the given pattern.
1
12
123
1234
12345
rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=' ')
print('')
5. Write a program in python to print the given pattern.
*
**
***
****
*****
rows = 5
for i in range(0, rows):
for j in range(0, i + 1):
print("*", end=' ')
print("\r")
6. Program to display the fabonacci series upto nth term.
nterms = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
OUTPUT:
How many terms? 7
Fibonacci sequence:
0
1
1
2
3
5
8
7. Write a program that creates a list of integers less than 100 that are multiples of
3 and 5.
L=[]
For x in range(1,100):
If x%3==0 and x%5==0:
i.append(i)
print(L)
8. . Program to find minimum value in a list.
L=eval(input('Enter list values'))
length=len(L) #length=6
min=L[0] #min=10
loc=-1
for i in range(length): #0,1,2,3,4,5
if L[i]<min:
min=L[i] #min=1
loc=i
print("Minimum value=",min)
print("location=”,loo)
9. Program to check whether a value exists in dictionary
aDict={'Bhavna':1,"Richard":2,"Firoza":3,"Arshnoor":4}
val=eval(input('Enter value'))
flag=0
for k in aDict:
if val==aDict[k]:
print("value found at key",k)
flag=1
if flag==0:
print("value not found")
10. Program to find largest among two numbers using a user
defined function .
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()
11. 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 rate="))
in1=interest(p,r,t)
print("Interest=",in1)
12. Program to use default arguments in a function.
def printinfo( name, age = 35 ): #default argument
print ("Name: ", name)
print ("Age ", age)
return
printinfo("aman",45)
printinfo("Parth")
13. . Program to write rollno, name and marks of a student in a
data file Marks.dat.
count=int(input('How many students are there in the class'))
fileout=open("Marks.dat","a")
for i in range(count):
print("Enter details of student",(i+1),"below")
rollno=int(input("Enter rollno:"))
name=input("name")
marks=float(input('marks'))
rec=str(rollno)+","+name+","+str(marks)+"\n"
fileout.write(rec)
fileout.close()
14. Program to read and display contents of file Marks.dat.
fileinp=open("Marks.dat","r")
while str:
str=fileinp.readline()
print(str)
fileinp.close()
15. Program to read and display those lines from file that start with
alphabet ‘T’.
file1=open("data.txt","r")
count=0
str1=file1.readlines()
print(str1)
for i in str1:
if i[0]=='T':
print (i)
file1.close()
16. Program to read and display those lines from file that end with
alphabet ‘n’.
file1=open("data.txt","r")
count=0
str1=file1.readlines()
for i in str1:
if i[-2]=='n':
count+=1
print("Number of lines which end with 'n'=",count)
file1.close()
17. Program to count number of characters in data file data.txt.
file1=open("data.txt","r")
ch=" "
count=0
while ch:
ch=file1.read(1)
count+=1
print("Number of characters=",count)
file1.close()
18. Program to write data in a csv file student.csv.
import csv
fh=open("d:\student.csv","w")
stuwriter=csv.writer(fh)
stuwriter.writerow([1,'aman',50])
stuwriter.writerow([2,'Raman',60])
fh.close()
19. Program to readand display data from a csv file student.csv.
import csv
fh=open("d:\student.csv","r")
stureader=csv.reader(fh)
for rec in stureader:
print(rec)
fh.close()
20. Program to count number of words in data file data.txt.
file1=open("data.txt","r")
line=" "
count=0
while line:
line=file1.readline()
s=line.split()
for word in s:
count+=1
print("Number of words=",count)
file1.close()
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‟.
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;
45
MB004 Unite3 New_Vision
0
30 Classic Mobile
MB001 Galaxy
0 Store
(viii) SELECT AVG(M_Price) FROM MobileMaster;
5450
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 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
viii. SELECT COUNT(*), SUM(FEES) FROM COURSE
WHERE STARTDATE< ‘2018-09-15’;
Ans.
4 65000
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 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
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 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
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’;
**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
SQL 6
Table: PRODUCT
Product Manufactu Pric
P_ID
Name rer e
TP0 TalcomPow
LAK 40
1 der
FW0
Face Wash ABC 45
5
BS01 Bath Soap ABC 55
SH0
Shampoo XYZ 120
6
FW1
Face Wash XYZ 95
2
Table: CLIENT
C_I
Client Name City P_ID
D
TalcomPowd FW0
01 Delhi
er 5
Mumba
06 Face Wash BS01
i
12 Bath Soap Delhi SH06
FW1
15 Shampoo Delhi
2
Banglor
16 Face Wash TP01
e
(i) To display the details of those Clients whose city is Delhi.
Ans: Select all from Client where City=”Delhi”
(ii) To display the details of Products whose Price is in the range of 50 to 100(Both values
included).
Ans: Select all from product where Price between 50 and 100
(iii) To display the ClientName, City from table Client, and ProductName and Price from table
Product, with their corresponding matching P_ID.
Ans: Select ClientName,City,ProductName, Price from Product,Client where
Product.P_ID=Client.P_ID.
(iv) To increase the Price of all Products by 10
Ans: Update Product Set Price=Price +10
(v) SELECT DISTINCT Address FROM Client.
Ans: ( The above question may consist DISTINCT City. If it is DISTINCT City, the following
is the answer)
City
-----
Delhi
Mumbai
Bangalore
******THE END******