You are on page 1of 48

INDEX

SN Topic Date Sign


o
1 Write a program to create a fibonacci series. 5/04/23

2 Write a program to sort elements of a list using 5/04/23


insertion sort.

3 Write a program half of even no. and double of odd 5/04/23


no in given list

4 Write a program to display frequencies of all 19/04/23


elements in a given list.

5 Write a program of function to display the details of 19/04/23


the employees who are earning between 20000 and
40000 considering a binary file 'emp.dat'

6 WAF that receives an octal no. and print equivalent 19/04/23


no in other no base ie in decimal, binary and
hexadecimal equivalents.

7 Write a program making digit function that generates 12/07/23


the 4 terms of AP by providing initial and step value
to function that returns the 1st four terms of the
series.

8 Write a program to create a random number 12/07/23


generator that generates random numbers between 1
and 6.

9 Write a program to count all the words starting with 19/07/23


vowels in a text file 'CS Poem.txt

10 Write a program to count all 4 letter words from a 19/07/23


text file 'CS Poem.txt

11 Write a program to read a text file line by line and 19/07/23


display each word separated by a #.
SN Topic Date Sign
o
12 Write a program to read data from a text file 'CS 02/08/2023
Poem.txt', and display words which have
maximum/minimum characters

13 Write a program that will write a string in binary file 02/08/23


'school.dat' and display the words of the string in
reverse order

14 Write a program in csv file 'Stock.csv' and also 02/08/23


display the content of the file.

15 Write a program to create a csv file and store emp no, 09/08/23
name, salary and search an emp no. and display the
data, If not found send appropriate message

16 Write a program to create a binary file with name and 09/08/23


roll number. Search for A given roll number and
display the name, if not found display appropriate
message

17 Write a program to remove an element from stack if 09/08/23


deleted all print underflow condition.

18 Write a program to remove all the lines that contain 04/10/23


the character 'a' in a file and write it to another file.

19 Write a program to implement a stack using a list 04/10/23

20 Write a program to create a CSV File by entering 04/10/23


user-id and password, read & search the password for
the given user-id.
SQL INDEX

SNo Topic Date Sign


1 WAQ to print SID, NAME, and GENDER of 16/08/23
students in class.

2 WAQ to print details of CS Students 16/08/23

3 WAQ to print details of female IP students of 16/08/23


class XI.

4 WAQ to print details of male students of class 16/08/23


XI.

5 WAQ to print details of those students whose 16/08/23


blood group is B+ and they are of class XI.

6 WAQ to print names of male students whose 13/09/23


birthday is in the month of February.

7 WAQ to print the name of students whose 13/09/23


surname is ‘Singh’?

8 WAQ to print the name of students whose 13/09/23


name’s second letter whose name’s second letter
is ‘a’

9 WAQ to print the NAME, CLASS, SECTION of 13/09/23


students whose birthday is in this or the next
month.

10 WAQ to print the details of those students who 13/09/23


are paying fees between 2.5K and 3K.

11 WAQ to print maximum, minimum and average 20/09/23


fees deposited by students.

12 WAQ to print details of those students who are 20/09/23


paying minimum fees.
SNo Topic Date Sign
13 WAQ to print details of the eldest student in 20/09/23
school.

14 WAQ to print the no. of student gender-wise. 20/09/23

15 WAQ to print the no. of students admissioned 20/09/23


category-wise.

16 WAQ to print the sum of fees paid by gender 27/09/23


wise.

17 WAQ to print the sum of fee class section wise. 27/09/23

18 WAQ to print the no. of student fees paid 27/09/23


amount wise.

19 WAQ to count the no. of students, dob month 27/09/23


wise.

20 WAQ to convert blood groups to A+ for those 27/09/23


students whose group is NA.
SQL CONNECTIVITY INDEX

SNo Topic Date Sign


1 Write a program to connect with SQL databases 23/08/23
and store employee's information & display
them.

2 Write a program to connect with SQL database 23/08/23


and search employee's no. in table and display
records. If not found, display appropriate
messages.

3 Write a program to connect with SQL database 11/10/23


and delete the record of entered employee no

4 Write a program to connect with SQL database 11/10/23


and update records of the employee no. as input
by the user for updation purpose
Q1. Write a program to create a fibonacci series.
Atul Singh Patel XII-Science

Code:
n=int(input("Enter no. : "))
a,b=0,1
print(a,end=" ")
for i in range(2,n+1):
print(b, end=" ")
a, b=b, a+b

Output:
Q2. Write a program to sort elements of a list using insertion sort.
Atul Singh Patel XII-Science

Code:
list1=eval(input("Enter your element:"))
for i in range(1, len(list1)):
key=list1[i]
j=i-1
while j>0 and key<list1[j]:
list1[j+1]=list1[j]
j=j-1
else:
list1[j+1]=key
print("List after sorting:", list1)

Output:
Q3. Write a program half of even no. and double of odd no in given list
Atul Singh Patel XII-Science

Code:

n=int(input("Enter your number: "))


if n%2==0:
print("Output (even): ", n/2)
else:
print("Output (odd): ", n*2)

Output:
Q4. Write a program to display frequencies of all elements in a given list.
Atul Singh Patel XII-Science

Code:
dic={}
list1 =eval(input("Enter a list:" ))

length = len(list1)

for i in range(length):
p=list1[i]
k=list1.count(list1[i])
dic[p]=k

[print(key,':',value) for key, value in dic.items()]

Output:
Q5. Write a program of function to display the details of the employees who are
earning between 20000 and 40000 considering a binary file 'emp.dat'.
Atul Singh Patel XII-Science

CODE:
import pickle
f = open('emp.dat', 'rb')
data = pickle.load(f)
print('## FILE CONTENT ##')
print('Emp_Name : Emp_Salary')
for key, value in data.items():
print(key, ':', value)
print('Employees earning salary b/w 20,000 and 40,000 are:')
for i in data:
sal = data[i]
if sal > 20000 and sal < 40000:
print(i, ':', sal)

Output:
Q6. WAF that receives an octal no. and print equivalent no in other no base ie in
decimal, binary and hexadecimal equivalents
Atul Singh Patel XII-Science

CODE:
def convert_octal(octal_num):
decimal_num = int(octal_num, 8)
binary_num = bin(decimal_num)
hex_num = hex(decimal_num)

print(f"Decimal equivalent: {decimal_num}")


print(f"Binary equivalent: {binary_num}")
print(f"Hexadecimal equivalent: {hex_num}")

octal_num=input("Enter the octal number:")


convert_octal(octal_num)

OUTPUT:
Q7. Write a program making digit a function that generates the 4 terms of an AP by
providing initial and step value to a function that returns the 1st four terms of
series.
Atul Singh Patel XII-Science

Code:
a=int(input("Enter First Term Of AP:" ))
d=int(input("Enter Common Difference AP:"))
print("First Term:", a, "\nSecond Term:", a + d, "\nThird Term:", a +
2*d,"\nFourth Term:", a + 3*d)

Output:
Q8. Write a program to create a random number generator that generates random
numbers between 1 and 6. (simulates a dice) [CBSE]
Atul Singh Patel XII-Science

Code:
import random
print("DICE SIMULATOR PYTHON")
k=random.randint(1,6)
print("Dice Number is", k)

Output:
Q9. Write a program to count all the words starting with vowels in a text file 'CS
Poem.txt'.
Atul Singh Patel XII-Science

Code:
with open(' There sandy seems the golden sky.txt') as file:
words=file.read()
print('file content')
print(words)
words=words.split()
count=0
for i in words:
if i[0] in ['a','i','e','o','u','A','I','E','O','U']:
count+=1
print('no. of words starting with vowel are: ',count)

Output:
Q10. Write a program to count all 4 letter words from a text file 'CS Poem.txt'.
Atul Singh Patel XII-Science

Code:
with open(' There sandy seems the golden sky.txt') as file:
words=file.read()
print('file content')
print(words)
words=words.split()
count=0
for i in words:
if len(i)==4:
count+=1
print('Number of four letter words in file are:',count)

Output:
Q11. Write a program to read a text file line by line and display each word
separated by a #. [CBSE]
Atul Singh Patel XII-Science

Code:
f=open('cspoem.txt','r')
for line in f:
words=line.split()
for w in words:
print(w+'#',end=' ')
print( )
f.close()

Output:
Q12. Write a program to read data from a text file 'CS Poem.txt', and display words
which have maximum/minimum characters.
Atul Singh Patel XII-Science

Code:
with open(' There sandy seems the golden sky.txt') as file:

words=file.read()

print('file content')

print(words)

words=words.split()

k=[]

b=[]

for i in range (len(words)):

words[i]=words[i].split()

length=len(str(words[i]))

k.append(length)

b.append(words[i])

print('words with maximum characters are: ',end=' ')

for i in range(len(k)):

if k[i]==max(k):

print(b[i],end=' ')

print('\nwords with minimum characters are: ',end=' ')

for j in range(len(k)):

if k[j]==min(k):

print(b[j],end=' ')
Output:
Q13. Write a program that will write a string in binary file 'school.dat' and display
the words of the string in reverse order.
Atul Singh Patel XII-Science

Code:
import pickle
str1='Python Computer-Science 2023-2024'
print("Original String:\n", str1)
with open("school.dat","wb") as file:
pickle.dump(str1,file)
print("String has been written in the file.")
with open ("school.dat", "rb") as file:
str1=pickle.load(file)
print("String in the binary file: ", str1)
str1=str1.split(' ')
str1.reverse()
print("String reversed is: ")
for i in str1:
print(i,end=" ")

Output:
Q14. Write a program in csv file 'Stock.csv' and also display the content of the file.
Atul Singh Patel XII-Science

Code:
import csv
clm=["Item_No.", "Item_Name", "Item_Price"]
row=[['1001','CPU','60000'], ['1002', 'LCD', '69000'], ['1003',
'Keyboard And Mouse', '8000']]
with open("stock.csv", "w", newline="") as file:
write_file=csv.writer(file)
write_file.writerow(clm)
for i in row:
write_file.writerow(i)
print("File has been created.")

with open("stock.csv", "r") as file:


read_file=csv.reader(file)
for i in read_file:
print('%8s'%i[0],'%25s'%i[1],'%25s'%i[2])

Output:
Q15. Write a program to create a csv file and store emp no, name, salary and search
an emp no. and display the data, If not found send appropriate message.
Atul Singh Patel XII-Science

Code:
import csv
with open('myfile.csv', mode='a') as csvfile:
mywriter=csv.writer(csvfile,delimiter=',')
ans='y'
while ans.lower()=='y':
eno=int(input("Enter Employee Number: "))
name=input("Enter Employee Name: ")
salary=int(input("Enter Employee Salary: "))
mywriter.writerow([eno,name,salary])
print('##Data Saved##')
ans=input("Add More ?")
ans='y'
with open('myfile.csv', 'r') as csvfile:
myreader = csv.reader(csvfile,delimiter=',')
while ans=='y':
found=False
e=int(input("Enter Employee Number to search: "))
for row in myreader:
if len(row)!=0:
if int(row[0])==e:
print("Name :", row[1])
print("Salary :", row[2])
found=True
break
if not found:
print("Emp no. not found")
ans=input("Search More? (y)")

Output:
Q16. Write a program to create a binary file with name and roll number. Search for
A given roll number and display the name, if not found display appropriate
message. [CBSE]
Atul Singh Patel XII-Science

Code:
import pickle
record=[]
def write():
f=open("student_details.dat","wb")
while True:
roll=int(input("Enter roll number: "))
name=input("Enter Name: ")
marks=int(input("Enter marks: "))
lst= [roll,name,marks]
record.append(lst)
ch=input("Enter 'Y/y' to enter more data")
if ch in "Yy":
continue
else:
break
pickle.dump(record,f)
f.close()
def read():
f= open("student_details.dat", "rb")
k=pickle.load(f)
print(k)
def update():
f=open("student_details.dat", "ab")
fr=open("student_details.dat", "rb")
while True:
lst=list(pickle.load(fr))
print(lst)
rno=int(input("Enter Roll Number: "))
name=input("Enter Name:")
marks=int(input("Enter marks:"))
lst2=[rno,name,marks]
lst.append(lst2)
fw=open('student_details.dat', 'wb')
pickle.dump(lst, fw)
ch=input("Enter n to end loop:")
if ch=='n':
break
print("Record Added")
f.close()
def search():
f=open("student_details.dat", "rb")
k=pickle.load(f)
inp=int(input("Enter roll number you want:"))
for i in k:
if i in k:
if i[0]==inp:
print("Record Found")
print(i)
else:
print("Record Not Found")
break

def mainmenu():
print("--"*35)
print("1. Write Data In Binary File\n2.Read Data in Binary
File\n3.Update Data In Binary File\n4.Search Data in Binary File")
ch=int(input("Enter your choice:"))
if ch==1:
write()
elifch==2:
read()
elifch==3:
update()
elifch==4:
search()
mainmenu()

Output:
Q17. Write a program to remove an element from stack if deleted all print
underflow condition.
Atul Singh Patel XII-Science

Code:
stk=eval(input('Enter the stack: '))
if stk==[]:
print('Stack is underflow case')
else:
stackelempop=stk.pop()
print(stackelempop,'has been deleted from stack')

Output:
Q18. Write a program to remove all the lines that contain the character 'a' in a file
and write it to another file. [CBSE]
Atul Singh Patel XII-Science

Code:
f=open('oldfile.txt','r')
lines=f.readlines()
fo=open('oldfile.txt','w')
fn=open('newfile.txt','w')
for line in lines:
if 'a' in line:
fn.write(line)
else:
fo.write(line)
fn.close()
fo.close()
print('data updated ')

Output:
Q19. Write a program to implement a stack using a list. [CBSE]
Atul Singh Patel XII-Science

Code:
list=[956,584]
list.append(1)
print("push:",list)
list.append(2)
print("push:",list)
list.append(3)
print("push:",list)
list.pop()
print("pop:",list)
print("peek:",list[-1])
list.pop()
print("pop:",list)
print("peek:",list[-1])

Output:
Q20. Write a program to create a CSV File by entering user-id and password, read
& search the password for the given user-id. [CBSE]
Atul Singh Patel XII-Science

Code:
import csv

def Menu():
print("Choose one\n1.Write\n2.Read")
ch=int(input("Enter Choice:"))
if ch==1:
Write()
elifch==2:
Read()

def Write():
with open("user_info.csv", "w") as obj:
fileobj = csv.writer(obj)
fileobj.writerow(["User Id", "password"])
while(True):
user_id = input("Enter ID: ")
password = input("Enter Password: ")
record = [user_id, password]
fileobj.writerow(record)
x = input("Press Y/y to continue and N/n to terminate the
program.\n")
if x in "Nn":
break
elif x in "Yy":
continue
def Read():
with open("user_info.csv", "r") as obj2:
fileobj2 = csv.reader(obj2)
given = input("Enter the user id to be searched\n")
for i in fileobj2:
next(fileobj2)
if i[0] == given:
print(i[1])
break
Menu()

Output:
MYSQL
SQL TABLE:-
SQL QUERIES:-
Q1. WAQ to print SID, NAME, and GENDER of students in class.
Atul Singh Patel XII-Science

Q2. WAQ to print details of CS Students.


Atul Singh Patel XII-Science
Q3. WAQ to print details of female IP students of class XI.
Atul Singh Patel XII-Science

Q4. WAQ to print details of male students of class XI.


Atul Singh Patel XII-Science

Q5. WAQ to print details of those students whose blood group is B+ and they are of
class XI.
Atul Singh Patel XII-Science
Q6. WAQ to print names of male students whose birthday is in the month of
February.
Atul Singh Patel XII-Science

Q7. WAQ to print the name of students whose surname is ‘Singh’?


Atul Singh Patel XII-Science

Q8. WAQ to print the name of students whose name’s second letter whose name’s
second letter is ‘a’.
Atul Singh Patel XII-Science
Q9. WAQ to print the NAME, CLASS, SECTION of students whose birthday is in
this or the next month.
Atul Singh Patel XII-Science

Q10. WAQ to print the details of those students who are paying fees between 2.5K
and 3K.
Atul Singh Patel XII-Science

Q11. WAQ to print maximum, minimum and average fees deposited by students.
Atul Singh Patel XII-Science
Q12. WAQ to print details of those students who are paying minimum fees.
Atul Singh Patel XII-Science

Q13. WAQ to print details of the eldest student in school.


Atul Singh Patel XII-Science

Q14. WAQ to print the no. of student gender-wise.


Atul Singh Patel XII-Science
Q15. WAQ to print the no. of students admissioned category-wise.
Atul Singh Patel XII-Science

Q16. WAQ to print the sum of fees paid by gender wise.


Atul Singh Patel XII-Science

Q17. WAQ to print the sum of fee class section wise.


Atul Singh Patel XII-Science
Q18. WAQ to print the no. of student fees paid amount wise.
Atul Singh Patel XII-Science

Q19. WAQ to count the no. of students, dob month wise.


Atul Singh Patel XII-Science
Q20. WAQ to convert blood groups to A+ for those students whose group is NA.
Atul Singh Patel XII-Science
SQL CONNECTIVITY QUESTIONS :-

Q1- WAP to connect with SQL database and store employee's information &
display them.
Atul Singh Patel XII-Science

Code:
import mysql.connector as mycon
con=mycon.connect(host='Localhost',user='root',password='4078')
cur=con.cursor()
cur.execute('use employe;')
con.commit()
choice=None
while choice!=0:
print('1. add record')
print('2. display record')
print('3. exit')
choice=int(input('enter your choice: '))
if choice ==1:
e=int(input('enter employee no.: '))
n=input('enter name of employee: ')
a=input('enter address of employee: ')
s=int(input('enter salary of employee: '))
d=input('enter department: ' )
query="insert into emp
value({},'{}','{}',{},'{}')".format(e,n,a,s,d)
cur.execute(query)
con.commit()
print('##DATA SAVED##')
elif choice==2:
query="select * from emp;"
cur.execute(query)
result=cur.fetchall()
print("%10s"%"E_NO","%20s"%"E_Name","%20s"%"address","%10s"%"salary",
"%15s"%"dept")
for row in result:

print("%10s"%row[0],"%20s"%row[1],"%20s"%row[2],"%10s"%row[3],"%15s"%
row[4])
elif choice==3:
con.close()
print("#BYE#")
break
else:
print('INVALID CHOICE')

Output:
Q2- WAP to connect with SQL database and search employee's no. in table and
display records. If not found, display appropriate message.
Atul Singh Patel XII-Science

Code:
import mysql.connector as mycon
con=mycon.connect(host='Localhost',user='root',password='4078',databa
se='employe')
cur=con.cursor()
print('#'*40)
print('employee search form')
print('#'*40)
ans='y'
while ans=='y':
eno=int(input('enter empno to search :'))
query="select * from emp where E_NO={};".format(eno)
cur.execute(query)
result=cur.fetchall()
if cur.rowcount==0:
print('sorry emp no not found')
else:

print("%10s"%"E_NO","%20s"%"E_Name","%20s"%"salary","%15s"%"dept")
for row in result:

print("%10s"%row[0],"%20s"%row[1],"%20s"%row[3],"%15s"%row[4])
choice=input('do you want to search more?: ')
if choice != 'Y':
break
Output:
Q3- WAP to connect with SQL database and delete the record of entered employee
no.
Atul Singh Patel XII-Science

Code:
import mysql.connector as mycon
con=mycon.connect(host='Localhost',user='root',password='4078',databa
se='employe')
cur=con.cursor()
print('#'*40)
print('employee updation form')
print('#'*40)
ans='y'
while ans=='y':
eno=int(input('enter eempno to update :'))
query="select * from emp where E_NO={};".format(eno)
cur.execute(query)
result=cur.fetchall()
if cur.rowcount==0:
print('sorry emp no not found')
else:

print("%10s"%"E_NO","%20s"%"E_Name","%20s"%"salary","%15s"%"dept")
for row in result:
list1=list(row)

print("%10s"%list1[0],"%20s"%list1[1],"%20s"%list1[3],"%15s"%list1[4]
)
choice=input('Are you sure to update?: ')
if choice.lower()=='y':
print('==you can update only debt and salary==')
print('==for emp no and name contact admin==')
d=input('enter new department')
if d=='':
d=list1[4]
try:
s=int(input('enter new salary'))
except:
s=list1[3]
query1="update emp set salary={},dept='{}' where
E_NO={}".format(s,d,eno)
cur.execute(query1)
con.commit()
print("RECORD UPDATED")
ans=input('update more?')

Output:
Q4- WAP to connect with SQL database and update records of the employee no. as
input by the user for updation purpose
Atul Singh Patel XII-Science

Code:
import mysql.connector as mycon
con=mycon.connect(host='Localhost',user='root',password='root',databa
se='employe')
cur=con.cursor()
print('#'*40)
print('employee updation form')
print('#'*40)
ans='y'
while ans=='y':
eno=int(input('enter eempno to update :'))
query="select * from emp where E_NO={};".format(eno)
cur.execute(query)
result=cur.fetchall()
if cur.rowcount==0:
print('sorry emp no not found')
else:

print("%10s"%"E_NO","%20s"%"E_Name","%20s"%"salary","%15s"%"dept")
for row in result:

print("%10s"%row[0],"%20s"%row[1],"%20s"%row[3],"%15s"%row[4])
choice=input('Are you sure to delete?: ')
if choice.lower()=='y':
query="delete from emp where E_NO={}".format(eno)
cur.execute(query)
con.commit()
print('##RECORD DELETED SUCCESSFULLY##')
ans=input('delete more(y)?: ')

Output:

You might also like