0% found this document useful (0 votes)
16 views23 pages

computer science practical file class 12

for class 12

Uploaded by

ddvarshney73
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)
16 views23 pages

computer science practical file class 12

for class 12

Uploaded by

ddvarshney73
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/ 23

#OUTPUT OF PROGRAM 1:-

# OUTPUT OF PROGRAM 2:-


# OUTPUT OF PROGRAM 3:-
# OUTPUT OF PROGRAM 4:-
#OUTPUT OF PROGRAM 5: -
PROGRAM#6: Write a program in python to display the size of a file
after removing EOL( end of line) characters, leading and trailing white
spaces and blank lines.

SOURCE CODE:

file=open(r' C:\Users\LENOVO\OneDrive\Desktop\dark theme.txt ',"r")


str1=" "
size=0
tsize=0
while
str1:
str1=file.readline()
size=size+len(str1.strip())
tsize=tsize+len(str1)
print("The total size of the file:",tsize)
print("size of the file after removing all EOL characters & blank lines:",size)
file.close()
# OUTPUT OF PROGRAM 6:-
#OUTPUT OF PROGRAM 7:-
#OUTPUT OF PROGRAM 7:-
#OUTPUT OF PROGRAM 8
#OUTPUT OF PROGRAM 9:-
#OUTPUT OF PROGRAM 10:-
#OUTPUT OF PROGRAM 11:-
PROGRAM#12: Write a python program to implement all stack
operations.

SOURCE CODE:--

############# STACK IMPLEMENTATION ##############

def
isempt(stack)
: if
stack==[]:
return
True else:
return False

def
push(stack,item
):
stack.append(ite
m)
top=len(stack)
+1
def
pop(stack,item
): if
isempt(stack):
return
"underflow" else:
top=len(stack)
==0 return
item
def peek(stack):
if isempt(stack):
return
"underflow" else:
top=len(stack)
+1 return
stack[top]
def
display(stack)
: if
isempt(stack)
:
print("stack is empty")
else:
top=len(stack)-1
print(stack[top])
for i in range(top-1,-1,-
1): print(stack[i])

# main
stck=[]
top=None

while True:
print("stack operations")
print("1,push")
print("2.pop")
print("3,peek"
)
print("4,display
")
print("5,exit")
ch=int(input("enter your choice(1-
5):")) if ch==1:
itm=int(input("enter an
item:")) push(stck,itm)
elif ch==2:
item=pop(stck,i
tm)
if item == "underflow":
print("underflow!! stack is
empty")
else:
print("popped item
is:",item) elif ch==3:
item=peek(stck)
if item=="underflow":
print("underflow! stack is
empty")
else:
print("topmost item
is:",item) elif ch==4:
display(stck)
elif ch==5:
brea
k else:
print("invalid choice!")
#OUTPUT OF PROGRAM 12:-
PROGRAM#19: - Write a program in python that fetches all the recordsfrom
the stud table of your database.

SOURCE CODE:-

import mysql.connector as sqltor

mycon=sqltor.connect(host="localhost", user="root", password="surya",


database="ajay")
if mycon.is_connected()==False:
print ("Error Connecting to MYSQL
database") cursor= mycon.cursor()
cursor.execute("select*from stud")
data =
cursor.fetchall() for
row in data:
print(row)
#OUTPUT OF PROGRAM 19: -
PROGRAM#20: -WRITE A PROGRAM IN PYTHON THAT FETCHES THE
NAMES OF THE STUDENT WHO HAVE “A” GRADE IN GAME1&GAME2.

SOURCE CODE: -

import mysql.connector as sqltor

mycon=sqltor.connect(host="localhost",user="root",password="surya",d

atabase
="ajay")

if mycon.is_connected()==False:
print("Error connecting to mysql

databse") cursor=mycon.cursor()

cursor.execute("select*from student_info where grade1='A'and grade2

='A' ") data=cursor.fetchall()

for s in
data:
print(s)

mycon.close()
#OUTPUT OF PROGRAM 20: -

You might also like