Practical file sample 22-23 - final - final
Practical file sample 22-23 - final - final
Kalyanpur
Session 2022-2023
Computer Science Project File
Submitted To: Submitted By:
Subject Teacher Name-
Class-
CERTIFICATE
This is to certify that <Your name here> of class XII (STREAM) of
<School name> has done his/her Practical on Python program and
Mysql queries under my supervision. He / She has taken interest
and has shown at most sincerity in completion of this project. I
certify this Project up to my expectation & as per guidelines issued
by CBSE, NEW DELHI.
Internal Examiner
External Examiner
Acknowledgement
It is with pleasure that I acknowledge my sincere gratitude to our
teacher, < Teacher name > who taught and undertook the
responsibility of teaching the subject computer science. I have
been greatly benefited from his/her classes.
My sincere thanks goes to our Principal <Principal name> who has
always been a source of encouragement and support and without
whose inspiration, this project would not have been a successful.
Finally, I would like to express my sincere appreciation for all the
other students for my batch their friendship & the fine times that
we all shared together.
Last but not least, I would like to thank all those who had helped
directly or indirectly towards the completion of this project.
Name of student
Class
Part A
Python programs
Q1: Write a python program to accept the percentage of student and display the
grade accordingly.
Ans:
per=float(input("Enter Percentage:"))
if per>85:
print("A")
elif per > 70 and per <=85:
print("B")
elif per > 60 and per <=70:
print("C")
elif per > 45 and per <=60:
print("D")
else:
print("E")
Q2: Write python program to check largest/smallest number among the three
inputted numbers.
Ans:
n1=int(input("Enter first number:"))
n2=int(input("Enter second number:"))
n3=int(input("Enter third number:"))
Q9: Give python code to accept values from the user up to a certain limit entered
by the user, if the number is even, then add it to a list.
Ans:
l=[]
n=int(input("No. of item:"))
for i in range(n):
a=int(input("Enter element:"))
if a%2==0:
l.append(a)
print(l)
Q10: Write a python program to create a dictionary with the roll number, name
and marks of n students in a class and display the names of students who have
marks above 75.
Ans:
d={}
n=int(input("Enter Limit:"))
for i in range(n):
roll_no=input("Enter Roll no.:")
name=input("Enter name:")
marks=int(input("Enter marks:"))
d[roll_no]=(name,marks)
print(d)
for i in d:
if d[i][1]>75:
print(d[i][0])
Q11. Write a user defined function in Python that displays the number of lines
starting with ‘H’ in the file story.txt. Eg: if the file contains:
Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.
st=[ ]
StackSize=3
def push():
y="y"
while y=="y":
sn=input("Enter name of student:")
if len(st)<StackSize:
st.append(sn)
else:
print("Stack is full!")
print(st)
break
y=input("Do you want to enter more name(y/n):")
Output:-
Q15: Julie has created a dictionary containing names and marks as key value
pairs of 6 students. Write a program, with separate user defined functions to
perform the following operations:
Push the keys (name of the student) of the dictionary into a stack, where
the corresponding value (marks) is greater than 75.
Pop and display the content of the stack.
ST=[]
for k in R:
if R[k]>75:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end=" ")
else:
break
Output:
Part B
SQL Queries
Answer the following questions according to given tables:
T_id Name Age Department Doj Salary Gender Adhar_no
1 Jugal gupta 34 CS 2017-01-10 12000 M 987655
2 Sharmilla 31 History 2008-03-24 20000 F 998877
3 Sandeep 32 Maths Null 30000 M 887766
4 Sangeeta 35 History 2015-07-01 40000 F 776655
5 Rakesh gupta 42 Maths 2007-09-05 25000 M Null
6 Shyam singh 50 History Null 30000 M 554433
7 Shiv om 44 CS 2017-02-25 21000 M 443322
8 Shalakha 33 Maths 2018-07-31 20000 F 332211
9 Shyam Kumar 35 Maths 2016-09-24 40000 M 221100
10 Moahn kumar 30 Maths 2016-09-24 25000 M 110022
Table: Teacher
Set1: ALTER table to add new attributes / modify data type / drop attribute
1) To Add new column “City” in teacher table.
Ans: alter table teacher add city varchar(20);
2) To rename column “City” to “T_City” in teacher table.
Ans: alter table teacher change city T_city varchar(30);
7) To display name, age and salary of those teacher who’s name ends with ‘a’.
Ans: select name,age,salary from teacher where name like "%a";
8) To display name, age and salary of those teacher who’s name contains letter ‘a’ at the second place.
Ans: select name,age,salary from teacher where name like "_a%";
9) To display name, age and salary of those teacher who’s name not having 7 character.
Ans: select name,age,salary from teacher where name like "_ _ _ _ _ _ _ ";
10) To display the number of all teacher whose name ends with ‘Kumar’.
Ans: select name,age,salary from teacher where name like "%kumar";
Set3: Insert into and Update Queries
11) Write query to add new data in T_id, name, department, salary column in ‘teacher’ table.
Ans: insert into teacher (t_id, name, department, salary) values (12, 'Arun kumar', 'CS',25000);
15) Query to delete all record at once free the memory of table.
Ans: truncate table teacher;
24) Write query to display number of teachers city-wise. Order by city name.
Ans: select place,count(place) from teacher natural join posting group by place order by place;
25) Write query to display number of teachers city-wise if in each city having more than 3 teachers order by city name.
Ans: select place,count(place) from teacher natural join posting group by place having count(place)>3;
Part C
Programs Based
on Python-SQL
Connectivity
Q1: Write a program to Creating database and Show database in Mysql through
Python.
Code:
import mysql.connector
mydb=mysql.connector.connect
(host="localhost",
user="root",
password="123456")
mycursor=mydb.cursor()
mycursor.execute("create database demo")
mycursor.execute("Show databases")
for i in mycursor:
print(i)
Q2: Write a program to Creating table inside any school database through
Python-Mysql connectivity program.
Code:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="123456",database="school")
mycursor=mydb.cursor()
mycursor.execute("create table std_details3\
(rno int primary key, name varchar(20), age int, city varchar(20))")
std=mycursor.execute("desc std_details3")
for i in mycursor:
print(i)
Q3: Write a program to Display all male teachers data from ‘teacher’ table using
fetchall() Through Python-Mysql connectivity program.
Code:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="123456",database="school")
mycursor=mydb.cursor()
mycursor.execute("select name,department from teacher where gender='m'")
myrecords=mycursor.fetchall()
for i in myrecords:
print(i)
print("Total number of rows retrieved",mycursor.rowcount)
Q4: Write a Parameterized program to insert data in std_details3 table Through
Python-Mysql connectivity program.
Code:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="123456",database="school")
mycursor=mydb.cursor()
y="y"
while y=="y":
r=int(input("Enter rollno:"))
n=input("Enter name:")
a=int(input("Enter age:"))
c=input("Enter City:")
mycursor.execute("insert into std_details3\
values({},'{}',{},'{}')".format(r,n,a,c))
mydb.commit()
print(mycursor.rowcount,"Record Inserted")
y=input("Do you want to insert more data:")
Thanks