Ishaan Manhas - Practical File
Ishaan Manhas - Practical File
S. No. PROGRAM
1 Write the definition of a function Alter (A,N) in python, which should change all the odd numbers in
the list to 1 and even
numbers to 0.
2 Write a code in python for a function Convert ( T, N) , which repositions all the elements of array by
shifting each of them
3 Write a function SWAP2BEST ( ARR, Size) in python to modify the content of the list in such a way that
the elements,
which are multiples of 10 swap with the value present in the very next position in the list.
4 Write function definition for SUCCESS(), to read the content of a text file STORY.TXT, and count the
presence of word
STORY and display the number of occurences of this word.
6 Write a program that reads character from the keyboard one by one. All lower case characters get
store inside the file
LOWER, all upper case characters get stored inside the file UPPER and all other characters get stored
inside OTHERS.
7 Write a definition for a function Economic() to read each record of a binary file ITEMS.DAT, find and
display those items
8 Write a function to search for a tablet from a binary file “table.dat”. The user should enter the model
no and function
9 Write a program to find how many 'firewall' or 'to’ are present in a file firewall.txt.
10 Write a python function to search and display the record of that product from the file PRODUCT.CSV
which has
maximum cost.
pid,pname,cost,quantity
p1,brush,50,200
p2,toothbrush,120,150
p3,comb,40,300
p4,sheets,100,500
p5,pen,10,250
12 Write the definition of a member function PUSH() in python to add a new book in a dynamic stack of
BOOKS considering
13 Write a function in python to delete a node containing book’s information, from a dynamically
allocated stack of books
14 Write a function in python PUSH (Arr), where Arr is a list of numbers. From this list, push all numbers
divisible by 5 into a
stack implemented by using a list. Display the stack if it has at least one element, otherwise display
appropriate error
message.
15 Write a function in python POP (Arr), where Arr is a stack implemented by a list of numbers. The
function returns the
b. Name of student
Write add(List) and pop(List) methods in python to add and remove from the stack.
17 Write SQL command for (a) to (f) and write the outputs for (g) on the basis of tables INTERIORS and
NEWONES.
18 Write SQL commands for (a) to (f) and write the outputs for (g) on the basis of table HOSPITAL.
19 Write a MySQL-Python connectivity code display ename, empno, designation, sal of those employees
whose salary is
more than 3000 from the table emp . Name of the database is “Emgt”.
20 Write a MySQL-Python connectivity code to increase the salary (sal) by 300 of those employees
whose designation (job) is clerk from the table emp. Name of the database is “Emgt”.
PROGRAMS
#Program 1
def Alter(A,N):
for i in range(N):
if (A[i]%2==0):
A[i]=0
else:
A[i]=1
D=[10,13,15,21]
print(“Original list”, d)
r=len(d)
Alter(d,r)
#OUTPUT
#Program 2
def Convert(T,N):
t=T[0]
for i in range(N-1):
T[i]=T[i+1]
T[N-1]=t
print("after conversion", T)
d=[10,14,11,21]
print("Original List", d)
r=len(d)
Convert(d,r)
#OUTPUT
#Program 3
def SWAP2BEST(A,size):
i=0
while(i<size):
if(A[i]%10==0):
A[i],A[i+1]=A[i+1],A[i]
i=i+2
else:
i=i+1
return(A)
d=[90,56,45,20,34,54]
print("actual list", d)
r=len(d)
#OUTPUT
#Program 4
def SUCCESS():
f=open("STORY.txt")
r=f.read()
c=0
for i in r.split():
if(i=="STORY"):
i=i.lower()
c=c+1
print(c)
f.close()
SUCCESS()
#Program 5
f=open(r"C:\Users\hp\Desktop\cs\networking\firewall.txt")
c=0
for i in f.readline():
if(i=='F'):
c=c+1
print(c)
#OUTPUT
#Program 6
f=open(r"C:\Users\user\Desktop\cs\networking\firewall.txt")
f1=open("lower.txt","a")
f2=open("upper.txt","a")
f3=open("others.txt","a")
r=f.read()
for i in r:
f1.write(i)
f2.write(i)
else:
f3.write(i)
f.close()
f1.close()
f2.close()
f3.close()
#Program 7
def Economic():
f1=open("items.dat","ab")
while True:
try:
g=pickle.load(f1)
if(g['cost']<250):
print(g)
except:
break
Economic()
#OUTPUT
enter id 2
#Program 8
def search():
f2=open("tablet.dat","rb")
while True:
try:
g=pickle.load(f1)
if g[0]==m:
print(g)
except:
break
f2.close()
search()
#OUTPUT
enter modelno 2
enter RAM 94
enter hd 56
{‘how many records’: 1, ‘modelno’: 2, ‘RAM’: 94, ‘hd’: 56, ‘details’: ‘beautiful brand new, gen 6 iPad’}
#Program 9
f=open(r"C:\Users\user\Desktop\cs\networking\firewall.txt")
t=f.read()
c=0
for i in t.split():
if(i=='firewall')or (i=='is'):
c=c+1
print(c)
#OUTPUT
#Program 10
import csv
def writecsv():
f=open("product.csv","w")
r=csv.writer(f,lineterminator='\n')
r.writerow(['pid','pname','cost','qty'])
r.writerow(['p1','brush','50','200'])
r.writerow(['p2','toothbrush','120','150'])
r.writerow(['p3','comb','40','300'])
r.writerow(['p5','pen','10','250'])
def searchcsv():
f=open("product.csv","r")
r=csv.reader(f)
next(r)
m=-1
for i in r:
if (int(i[2])>m):
m=int(i[2])
d=i
print(d)
writecsv()
searchcsv()
#OUTPUT
#Program 11
f=open(r"C:\Users\hp\Desktop\cs\networking\firewall.txt")
c=0
for i in f.readline():
if(i=='F'):
c=c+1
print(c)
#OUTPUT
#Program 12
s=[]
def push():
t=input("enter title")
l=[a,t]
s.append(l)
def disp(s):
if(s==[]):
print("list is empty")
else:
top=len(s)-1
print(s[top],"---top")
for i in range(top-1,-1,-1):
print(s[i])
push()
disp(s)
#OUTPUT
enter ISBN no 2
#Program 13
s=[]
def pop():
if(s==[]):
print("stack is empty")
else:
Book_no,Book_title=s.pop()
print("element deleted")
def disp(s):
if(s==[]):
print("list is empty")
else:
top=len(s)-1
print(s[top],"---top")
for i in range(top-1,-1,-1):
print(s[i])
pop()
disp(s)
#OUTPUT
stack is empty
list is empty
#Program 14
st=[]
def PUSH(Arr):
for i in Arr:
if(i%5==0):
st.append(i)
if(len(st)<0):
print(st)
else:
print("stack empty")
#OUTPUT
stack empty
#Program 15
def POP(Arr):
if(len(st)>0):
r=st.pop()
return r
else:
print("stack empty")
#OUTPUT
Blank
#Program 16
List=[]
def add(List):
name=input("Enter name")
item=[rno,name]
List.append(item)
def pop(List):
if len(List)>0:
List.pop()
else:
print("Stack is empty")
def disp(s):
if(s==[]):
print("list is empty")
else:
top=len(s)-1
print(s[top],"---top")
for i in range(top-1,-1,-1):
print(s[i])
add(List)
add(List)
disp(List)
pop(List)
disp(List)
#OUTPUT
[1, 'reena']
#Program 17
#Program 18
#Program 19
import mysql.connector as m
db=m.connect(host="localhost",user="root",passwd="1234",database="Emgt")
c=db.cursor()
for i in r:
print(i)
#Program 20
import mysql.connector as m
db=m.connect(host="localhost",user="root",passwd="1234",database="Emgt")
c=db.cursor()
db.commit()