class 12 cs project hdb in python
class 12 cs project hdb in python
ROLL NO.:-24
S.NO TOPIC REMARK
2
Write a program using user defined function
SQUARE_LIST(L), where L is the list of elements passed as
argument to the function. The function returns another list
named ‘SList’ that stores the Squares of all Non-Zero
Elements of L.
3
Write a function program using user defined function
REVERSE_DATA(str) that reads a string/sentence and
create a new sentence/ string storing each of the word in its
reverse form.
4 Write a program that allow the user to enter the eid, ename,
age, dept of n employees and write the detail of these
employees in the text file “emp.text”.
5
Write a program to add two more records i.e. detail of two
more employees in the file “emp.text” created in the program
no. 3 and then display the contents of the file.
6
Write a program using user defined function count_line() that count
the number of lines starting with letter ‘A’ or ‘T’ from the file
“data.text” and display it on the screen.
7
Write a program using user defined function count_word() to count
the words "are" and "the" in the file “stud.text”.
8
Write a program using user defined function count_vowel() to count
the number of vowels in the file “data.txt”
11
Write a program to display the detail of the
employee from the file "emp.dat" as per the eid
entered.
12
Consider a binary file ”flight.dat” that store the
information . WAP to display information of those
flights whose starting point is Delhi.
13 Write a program using user defined function in
Python WordCount() to read a text file
“Mydiary.txt” and display the number of words
present in each line
16
WAP to create a csv file “student.csv” to store data
Obtain the detail of five students from the user and
write it in the file
17 Sameer is a Python programmer. He has created a
csv file to store the details of the different
furnitures in form a list
20 Write the SQL commands for the question from (i) to (x) on
the basis of table TEACHER given below and Write SQL
commands for the following statements
30
Consider the table “student” in database
“test”WAP to display the detail of all students from
the table “student” of database “dps”.
31
WAP to display the detail of student whose rollno is entered
by the user from the table “student” of database “dps”
32
WAP to display the detail of all students who have
submitted the project from the table “student” of
database “test”.
33
WAP to insert a new record in the table “student”
of database “dps”.
34
WAP to display to increase the marks by 5 of all the
students of section ‘A’ from the table “student” of
database “dps”.
35
WAP to display to remove the record of the students whose
rollno is entered by the user from the table “student” of
database “dps”.
Q1. Write a program using user defined function FIND_LEN(str) that reads a string/line and
print each individual word of the line along with the length of the word.
def FIND_LEN(string):
a=string.split()
for i in a:
string=input("enter a line")
FIND_LEN(string)
Q2. Write a program using user defined function SQUARE_LIST(L), where L is the list of
elements passed as argument to the function. The function returns another list named ‘SList’
that stores the Squares of all Non-Zero Elements of L.
def SQUARE_LIST(L):
b=0
a=[]
for i in L:
if i!=0:
b=i*i
a.append(b)
print(a)
c=[1,4,67,7,0,8,0]
SQUARE_LIST(c)
Q3. Write a function program using user defined function REVERSE_DATA(str) that reads
a string/sentence and create a new sentence/ string storing each of the word in its reverse
form.
def REVERSE_DATA(str1):
k = str1.split()
x = []
str2 = ""
for i in range(0,len(k)):
x.append(k[i][::-1])
for j in range(0,len(x)):
REVERSE_DATA(str1)
Q4. Write a program that allow the user to enter the eid, ename, age, dept of n employees and
write the detail of these employees in the text file “emp.text”.
def employee_details(n):
for i in range(n):
file.write("Employee ID: " + eid + ", Name: " + ename + ", Age: " + age + ", Department: " + dept )
file.close()
employee_details(n)
Q5. Write a program to add two more records i.e. detail of two more employees in the file
“emp.text” created in the program no. 3 and then display the contents of the file.
def add_2_det(a):
for i in range(a):
file.write("Employee ID: " + eid + ", Name: " + ename + ", Age: " + age + ", Department: " + dept )
file.close()
add_2_det(2)
fp=open("data.txt")
if line.strip().startswith(('a', 't')):
print(line)
file_name = "data.text"
result = count_line(file_name)
Q7. Write a program using user defined function count_word() to count the words "are" and
"the" in the file “stud.text”.
def count_word()
a=0
fp=open("stud.txt", 'r')
for i in fp:
words = i.strip().split()
a += words.count("are") + words.count("the")
result = count_word()
Q8. Write a program using user defined function count_vowel() to count the number of
vowels in the file “data.txt”
def count_vowel():
a=0
vowels = "aeiouAEIOU"
fp=open("data.txt", 'r')
if char in vowels:
a += 1
count_vowel()
Q9. Write a program to write multiple records of students(rno, name, subject, marks)
in form of lists in a file "dps.dat" and then display all data on the screen.
import pickle
def write_records():
while True:
for i in range(n):
pickle.dump(record, file)
if ch = “y”or “Y”:
break
def copybinary():
fp2=open("target.dat","wb")
a=pickle.load(fp)
while True:
pickle.dump(a, fp2)
Q11. Write a program to display the detail of the employee from the file
"emp.dat" as per the eid entered by the user. Consider the binary file “emp.dat”
that contains the information of employees like (eid, ename, salary) in form of
list.
import pickle
def findemp():
a=pickle.load(fp)
b=a.split(":")
for i in b:
if eid==int([0]):
import pickle
def findflight():
fp=open("flight.dat","rb")
b=pickle.load(fp)
for i in len(b):
if i[2]==a:
def WordCount():
fp=open("Mydiary.txt", "r")
no = 1
words = len(line.split())
no += 1
def INDEX_LIST(l):
l2= []
for i in range(len(l)):
if l[i] != 0:
l2.append(i)
return l2
result = INDEX_LIST(L)
print("List:", L)
import pickle
def update_salary():
employees = []
while True:
record = pickle.load(file)
employees.append(record)
employee[2] += 2000
pickle.dump(employee, file)
update_salary()
Q16. WAP to create a csv file “student.csv” to store data (rollno,
name, marks). Obtain the detail of five students from the user and
write it in the file “student.csv”
import csv
def add_details():
for i in range(5):
ab=[rollno,name,marks]
wo=csv.writer(fp)
wo.writerow(ab)
add_details()
Q17. Sameer is a Python programmer. He has created a csv file named “furniture.csv” to store
the details of the different furnitures in form a list [Fid, Fname, Fprice] .Now Sameer wants to
write the following user defined functions:
(a) addDetail() – To accept the details of furniture items and add data in the csv file
“furniture.csv”. The column heading should also be added on top of the csv file.
(b) search()- To display the records of the furniture whose price is more than 10000
import csv
def addDetail():
fp= open("furniture.csv","w")
writer = csv.writer(fp)
for i in range(n):
def search():
reader = csv.reader(file)
[Rollno, Name, Subject, Marks] . For efficiently maintaining data of the examination, Tushar
wants to write the following user defined functions:
(a) addStudent() – To accept the details of five students and store data [rollno, name,
subject, marks] in the csv file “dps.csv”.
search()- To display the records of the students whose marks is more than
import csv
def addStudent():
writer = csv.writer(fp)
for i in range(5):
def search():
reader = csv.reader(file)
Q.19 Write SQL query to create a table ‘Workshop’ with the following structure:
CREATE TABLE Workshop (
WorkshopDate DATE,
NumSpeakers INTEGER,
Address VARCHAR(50)
);
Q.20 Write the SQL commands for the question from (i) to (x) on the basis of table
TEACHER given below:
i) DELETE FROM TEACHER WHERE TNo = 107;
ii) DELETE FROM TEACHER;
iii) ALTER TABLE TEACHER ADD PhoneNo VARCHAR(15);
iv) ALTER TABLE TEACHER MODIFY Tname VARCHAR(40)
v) SELECT Department, AVG(Salary) AS AvgSalary
FROM TEACHER
GROUP BY Department;
ix) SELECT *
FROM TEACHER
FROM TEACHER
Q21. Consider the following tables STORE and SUPPLIERS and answer the given
questions:
Table : STORE
SUPPLIER
i)SELECT *
FROM STORE
iii) SELECT *
FROM STORE
FROM STORE
GROUP BY Scode;
Q 22.Consider the above tables STORE and SUPPLIERS given in Q.No. 18 and Give the
output of the following SQL queries:
Table : Student
FROM Student;
Q24. Consider the table Student given in Q.No. 23 and give the output
of the following SQL queries:
1)4
2)900
3)Priyanka 19 Computer
Rahul 31 Computer
Rashmi 22 Maths
Ankit 20 M
Priyanka 19 F
Rahul 31 M
Payal 23 F
Sanket 29 M
Q25. Consider the following tables CLUB and COACH. Write SQL queries for
the following statements.
FROM CLUB;
FROM CLUB
ON CLUB.CoachID = COACHES.CoachID;
Q26. Consider the following tables CLUB and COACHES given in give the
output of the following SQL queries :
i)5
ii)34
101 KUKREJA
108 MOHIT
111 ABHISHEK
104 TARUN
travel = []
def Push_Element(NList):
global travel
for i in NList[::-1]:
travel.append(i)
print(travel)
def Pop_Element():
global travel
print(travel.pop())
if len(travel)==0:
print("Stack is empty")
L = [[11, "Sarthak", 92], [12, "Hardik", 95], [13, "Ravi", 80], [14, "Tushar", 99], [15, "Sangeeta", 75]]
Push_Element(L)
Pop_Element()
Q28. Rohit has a list containing 10 integers. You need to help him create a program with
separate user defined functions to perform the following operations based on this list.
● Traverse the content of the list and push the even numbers into a stack.
● Pop and display the content of the stack
def Pusheven():
nlist=[]
for i in a[::-1]:
if i%2==0:
nlist.append(i)
print(nlist)
Pusheven()
def pop(stack):
while stack:
print(stack.pop())
Q29. Ankur has a list containing 10 integers. You need to help him create a
program with separate user defined functions to perform the following
operations based on this list.
● Traverse the content of the list in reverse order i.e. read the content of list
from the last(end) and push the numbers into a stack.
● Pop and display the content of the stack.
for i in reversed(numbers):
stack.append(i)
def pop(stack):
while stack:
print()
def main():
if len(numbers) != 10:
push(stack, numbers)
pop(stack)
import mysql.connector
def connect_to_db():
user="stdent",
password="dps",
database="dps" )
return connection
def display_all_students(connection):
cursor = connection.cursor()
results = cursor.fetchall()
print(row)
Q31. WAP to display the detail of student whose rollno is entered by the
user from the table “student” of database “test”.
def display_student_by_rollno(connection):
cursor = connection.cursor()
result = cursor.fetchone()
if result:
else:
cursor = connection.cursor()
def display_students_with_project(connection):
cursor = connection.cursor()
results = cursor.fetchall()
print(row)
Q.33 WAP to display the detail of all students who have submitted the
project from the table “student” of database “test”.
import mysql.connector as mydb
cursor = connection.cursor()
def insert_new_student(connection):
cursor = connection.cursor()
query = "INSERT INTO student (rollno, name, marks, section, project_submitted) VALUES (%s, %s,
%s, %s, %s)"
connection.commit()
def increase_marks_section_a(connection)
cursor = connection.cursor()
connection.commit()
def remove_student_by_rollno(connection):
cursor = connection.cursor()
connection.commit()