[go: up one dir, main page]

0% found this document useful (0 votes)
20 views16 pages

Ishaan Manhas - Practical File

Uploaded by

vinoddahiya1986
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views16 pages

Ishaan Manhas - Practical File

Uploaded by

vinoddahiya1986
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

INDEX

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

to next position and shifting first element to last position.

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.

5 Write a program to find no of lines starting with ‘F’ in firewall.txt.

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

which cost less than 2500.

8 Write a function to search for a tablet from a binary file “table.dat”. The user should enter the model
no and function

should search and display the details of the tablet.

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.

Sample of product.csv is given below:

pid,pname,cost,quantity

p1,brush,50,200

p2,toothbrush,120,150

p3,comb,40,300

p4,sheets,100,500

p5,pen,10,250

11 Write a program to find no of lines starting with F in firewall.txt.

12 Write the definition of a member function PUSH() in python to add a new book in a dynamic stack of
BOOKS considering

the following code is already included in the program: ISBN, TITLE.

13 Write a function in python to delete a node containing book’s information, from a dynamically
allocated stack of books

implemented with the help of the following structure: BNo, BName.

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

value deleted from the stack.

16 A linear stack called "List" contains the following information:

a. Roll Number of student

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

print(“List after alteration”, A)

D=[10,13,15,21]

print(“Original list”, d)

r=len(d)
Alter(d,r)

#OUTPUT

Original list [10,13,15,21]

List after alteration [0,1,1,1]

#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

Original List [10, 14, 11, 21]

after conversion [14, 11, 21, 10]

#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)

print("after swapping", SWAP2BEST(d,r))

#OUTPUT

actual list [90, 56, 45, 20, 34, 54]

after swapping [56, 90, 45, 34, 20, 54]

#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:

if(i>='a' and i<='z'):

f1.write(i)

elif(i>='A' and i<='Z'):

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 giftname flowers

enter id 2

enter cost 500

{'giftname': ' flowers', 'id': 2, 'cost': 500.0}

#Program 8
def search():

f2=open("tablet.dat","rb")

m=int(input("enter the model no which you want to search"))

print("\n records satisfy the condition are \n")

while True:

try:

g=pickle.load(f1)

if g[0]==m:

print(g)

except:

break

f2.close()

search()

#OUTPUT

enter how many records 1

enter modelno 2
enter RAM 94

enter hd 56

details beautiful brand new, gen 6 iPad

{‘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

['p2', 'toothbrush', '120', '150']

#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():

a=int(input("enter ISBN no"))

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

enter title Encyclopedia

[2, ' Encyclopedia’] ---top

#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):

rno=int(input("Enter roll number"))

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])

#Call add and pop function to verify the code

add(List)

add(List)

disp(List)
pop(List)

disp(List)

#OUTPUT

Enter roll number 1

Enter name reena

Enter roll number 2

Enter name teena

[2, 'teena'] ---top

[1, 'reena']

[1, 'reena'] ---top

#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()

c.execute("select * from emp where sal>3000")


r=c.fetchall()

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()

c.execute("update emp set sal=sal+300 where job=”clerk”)

db.commit()

You might also like