0% found this document useful (0 votes)
11 views1 page

Www Scribd

Uploaded by

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

Www Scribd

Uploaded by

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

Search

Class-12-Computer
Science Practical File
2023-24
Uploaded by kalpanapradhan1179

 73% (22) · 59K views · 45 pages


AI-enhanced title and description

Document Information 
The document provides a practical file for a student'…

Download now

Download as pdf or txt

AISSCE-2023-24
PRACTICAL FILE

COMPUTER SCIENCE (083)

Student Name :

Grade :

Roll No. :

SUBMITTED TO
PRAFULLA KUMAR GOUDA
PGT COMPUTER SCIENCE)

Ad Download to read ad-free

Certificate
You're Reading a Preview
Upload your documents to download.

This is to certify that __________________________________________


Upload to Download
student of Class XII Science / Commerce has successfully completed their computer

Science New-083) Practical File.


OR

Become a Scribd member to read and download full


documents.
Internal Examiner External Examiner
Start your 30 day free trial

Principal

Page 2 of 45

Ad Download to read ad-free

PRACTICAL FILE- COMPUTER SCIENCE (083)

LIST OF PRACTICALS (2023-24)

You're Reading a Preview


CLASS-XII
1 Write a program to check a number whether Submission Teacher’s

it isUpload your documents to download.


Date Sign
palindrome or not.

2 Write a program to display ASCII code of a


Upload
character and vice versa. to Download
3 Program make a simple calculator.

4 Example of Global and Local variables in


function OR
5 Python program to count the number of
vowels, consonants, digits and special
Become a Scribd
characters member to read and download full
in a string
6 Python Program to add marks and calculate
the grade of a student
documents.

Start your 30 day free trial


7 Generating a List of numbers Using For Loop
8 Write a program to read a text file line by line
and display each word separated by '#'.
9 Read a text file and display the number of
vowels/ consonants/ uppercase/ lowercase
characters and other than character and digit
in the file.
10 Write a Python code to find the size of the file
in bytes, the number of lines, and number of
words and no. of character.
11 Create a binary file with the name and roll
number. Search for a given roll number and
display the name, if not found display
appropriate message.
Page 3 of 45

Ad Download to read ad-free

12 Create a binary file with roll number, name


and marks. Input a roll number and update
details. Create a binary file with roll number,
You're Reading a Preview
name and marks. Input a roll number and
update details.
13
Upload
# Write your
a program documents
to perform read andto download.
write
operation onto a student.csv file having fields
as roll number, name, stream and

14
percentage.
Upload to Download
Write a program to create a library in python
and import it in a program.
15 Take a sample of ten phishing e-mails (or any
OR
text file) and find the most commonly
occurring word(s).
16 Write a python program to implement a stack
Become
usingaa Scribd member to read and download full
list data-structure.
17 Write a program to implement a queue using
a list data structure.
documents.
18 SQL Queries

19 Startto your
Write a program connect30 daywith
Python free trial
MySQL using database connectivity and
perform the following operations on data in
database: Fetch, Update and delete the data.

PRAFULLA KUMAR GOUDA SIGNATURE OF EXTERNAL EXAMINER


PGT (COMPUTER SCIENCE)
INTERNAL EXAMINER

Page 4 of 45

Ad Download to read ad-free

Practical No-1

# Write a program to check a number whether it is palindrome or not.

SOURCE CODE:
You're Reading a Preview
num=int(input("Enter a number : "))

n=num Upload your documents to download.


res=0

while num>0: Upload to Download


rem=num%10

res=rem+res*10

num=num//10 OR
if res==n:

Become a Scribd
print("Number member to read and download full
is Palindrome")

else:
documents.
print("Number is not Palindrome")

Start your 30 day free trial

Output -

Page 5 of 45

Ad Download to read ad-free

Practical No-2

# Write a program to display ASCII code of a character and vice versa.

var=True
You're Reading a Preview
while var:
Upload your documents
choice=int(input("Press-1 to find the ordinalto download.
value of a character \nPress-2

to find a character of a value\n"))

if choice==1: Upload to Download


ch=input("Enter a character : ")

print(ord(ch))

elif choice==2: OR
val=int(input("Enter an integer value: "))

Become a Scribd member to read and download full


print(chr(val))

else:
documents.
print("You entered wrong choice")

Start
print("Do you want your 30
to continue? day
Y/N") free trial
option=input()

if option=='y' or option=='Y':

var=True

else:

var=False

Output -

Press-1 to find the ordinal value of a character

Press-2 to find a character of a value

Page 6 of 45

Ad Download to read ad-free

Enter a character : a

97
You're Reading a Preview
Do you want to continue? Y/N

YUpload your documents to download.


Press-1 to find the ordinal value of a character

Press-2 to findUpload
a characterto
of Download
a value

Enter an integer value: 65

A OR
Do you want to continue? Y/N

Become a Scribd member to read and download full


documents.

Start your 30 day free trial

Page 7 of 45

Ad Download to read ad-free

Practical No-3

# Program make a simple calculator

You're Reading a Preview


# This function subtracts two numbers

def subtract(x, y):


Upload
return x-y your documents to download.
# This function multiplies two numbers

def multiply(x, y): Upload to Download


return x * y

# This function divides two numbers

def divide(x, y): OR


return x / y

Become a Scribd
print("Select member to read and download full
operation.")

print("1.Add")
documents.
print("2.Subtract")

Start
print("3.Multiply") your 30 day free trial
print("4.Divide")

while True:

# take input from the user

choice = input("Enter choice(1/2/3/4): ")

# check if choice is one of the four options

if choice in ('1', '2', '3', '4'):

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

if choice == '1':

Page 8 of 45

Ad Download to read ad-free

print(num1, "+", num2, "=", add(num1, num2))

elif choice == '2':

You're Reading a Preview


print(num1, "-", num2, "=", subtract(num1, num2))

elif choice == '3':


Upload
print(num1,your documents
"*", num2, to download.
"=", multiply(num1, num2))

elif choice == '4':

print(num1, Upload to divide(num1,


"/", num2, "=", Download num2))

# check if user wants another calculation

# break the while loop if answer is no


ORdo next calculation? (yes/no): ")
next_calculation = input("Let's

if next_calculation == "no":

Become a Scribd member to read and download full


break

else:
documents.
print("Invalid Input")

Output - Start your 30 day free trial


Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4): 3
Enter first number: 15
Enter second number: 14
15.0 * 14.0 = 210.0
Let's do next calculation? (yes/no): no

Page 9 of 45

Ad Download to read ad-free

Practical No-4

# Example of Global and Local variables in function

You're Reading a Preview


x = "global "

def display():Upload your documents to download.


global x

y = "local" Upload to Download


x=x*2

print(x)

print(y) OR
display()

Become a Scribd member to read and download full


Output - documents.

global global Start your 30 day free trial


local

Page 10 of 45

Ad Download to read ad-free

Practical No-5

# Python program to count the number of vowels, consonants, digits and


special characters in a string
You're Reading a Preview
str = input(“Enter the string : “)

vowels = 0 Upload your documents to download.


digits = 0

consonants = 0
Upload to Download
spaces = 0

symbols = 0

str = str.lower() OR
for i in range(0, len(str)):

if(str[i] == ‘a’or str[i] == ‘e’ or str[i] == ‘i’


Become a Scribd member to read and download full
or str[i] == ‘o’ or str[i] == ‘u’):
documents.
vowels = vowels + 1

elif((str[i] >= ‘a’and str[i] <= ‘z’)):


Start your 30 day free trial
consonants = consonants + 1

elif( str[i] >= ‘0’ and str[i] <= ‘9’):

digits = digits + 1

elif (str[i] ==’ ‘):

spaces = spaces + 1

else:

symbols = symbols + 1

print(“Vowels: “, vowels);

print(“Consonants: “, consonants);

print(“Digits: “, digits);
Page 11 of 45

Ad Download to read ad-free

print(“White spaces: “, spaces);

print(“Symbols : “, symbols);

You're Reading a Preview


Output -
Upload your documents to download.
Enter the string : 123 hello world $%&45

Volwels: 3

Consontants: 7 Upload to Download


Digits: 5

White spaces: 3

Symbols: 3
OR

Become a Scribd member to read and download full


documents.

Start your 30 day free trial

Page 12 of 45

Ad Download to read ad-free

Practical No-6

# Python Program to add marks and calculate the grade of a student

You're Reading a Preview


total=int(input("Enter the maximum mark of a subject: "))

sub1=int(input("Enter marks of the first subject: "))


Uploadmarks
sub2=int(input("Enter yourofdocuments to"))download.
the second subject:

sub3=int(input("Enter marks of the third subject: "))

Upload
sub4=int(input("Enter marks to Download
of the fourth subject: "))

sub5=int(input("Enter marks of the fifth subject: "))

average=(sub1+sub2+sub3+sub4+sub5)/5

print("Average is ",average) OR
percentage=(average/total)*100

Become a Scribd
print("According member
to the percentage, ") to read and download full
if percentage >= 90:
documents.
print("Grade: A")

elif percentage >= 80Start your 30


and percentage day
< 90: free trial
print("Grade: B")

elif percentage >= 70 and percentage < 80:

print("Grade: C")

elif percentage >= 60 and percentage < 70:

print("Grade: D")

else:

print("Grade: E")

Page 13 of 45

Ad Download to read ad-free

Output -

You're Reading a Preview


Enter the maximum mark of a subject: 10

Enter marks of the first subject: 8

Enter marksUpload your


of the second documents
subject: 7 to download.
Enter marks of the third subject: 9

Enter marks of the fourthUpload


subject: 6 to Download
Enter marks of the fifth subject: 8

Average is 7.6

According to the percentage, OR


Grade: C

Become a Scribd member to read and download full


documents.

Start your 30 day free trial

Page 14 of 45

Ad Download to read ad-free

Practical No-7

# Generating a List of numbers Using For Loop

import random
You're Reading a Preview
randomlist = []
Upload
for i in range(0,5): your documents to download.
n = random.randint(1,30)

randomlist.append(n) Upload to Download


print(randomlist)

Output - OR

Become
[10, a Scribd
5, 21, 1, 17] member to read and download full
documents.

Start your 30 day free trial

Page 15 of 45

Ad Download to read ad-free

Practical No-8

# Write a program to read a text file line by line and display each word
separated by '#'.
You're Reading a Preview
filein = open("Mydoc.txt",'r')
for line in filein:
Upload your documents to download.
word= line .split()
for w in word:
print(w + '#',end ='')Upload to Download
print()
filein.close()
OR
OR

fin=open("D:\\python programs\\Book.txt",'r')

Become a Scribd
L1=fin.readlines( ) member to read and download full
s=' '
documents.
for i in range(len(L1)):
L=L1[i].split( )
Start your 30 day free trial
for j in L:
s=s+j
s=s+'#'
print(s)
fin.close( )
Output -
Text in file:
hello how are you?
python is case-sensitive language.
Output in python shell:
hello#how#are#you?#python#is#case-sensitive#language.#
Page 16 of 45

Ad Download to read ad-free

Practical No-9

# Read a text file and display the number of vowels/ consonants/ uppercase/
lowercase characters and other than character and digit in the file.
You're Reading a Preview
filein = open("Mydoc1.txt",'r')

Upload
line = filein.read() your documents to download.
count_vow = 0

count_con = 0
Upload to Download
count_low = 0

count_up = 0

count_digit = 0 OR
count_other = 0

print(line)
Become a Scribd member to read and download full
for ch in line:
documents.
if ch.isupper():

count_up +=1
Start your 30 day free trial
if ch.islower():

count_low += 1

if ch in 'aeiouAEIOU':

count_vow += 1

if ch.isalpha():

count_con += 1

if ch.isdigit():

count_digit += 1

if not ch.isalnum() and ch !=' ' and ch !='\n':

count_other += 1
Page 17 of 45

Ad Download to read ad-free

print("Digits",count_digit)

print("Vowels: ",count_vow)
You're Reading a Preview
print("Consonants: ",count_con-count_vow)

print("UpperUpload your documents


Case: ",count_up) to download.
print("Lower Case: ",count_low)

print("other than letters Upload to Download


and digit: ",count_other)

filein.close()
OR

Become a Scribd member to read and download full


documents.

Start your 30 day free trial

Page 18 of 45

Ad Download to read ad-free

Practical No-9

# Remove all the lines that contain the character `a' in a file and write it to
another file

f1 = open("Mydoc.txt")
You're Reading a Preview
Upload your documents
f2 = open("copyMydoc.txt","w") to download.
for line in f1:

if 'a' not in line:


Upload to Download
f2.write(line)

print('## File Copied Successfully! ##')

f1.close() OR
f2.close()

f2 = open("copyMydoc.txt","r")
Become a Scribd member to read and download full
print(f2.read())
documents.

Start your 30 day free trial

Page 19 of 45

Ad Download to read ad-free

Practical No-10

# Write a Python code to find the size of the file in bytes, the number of lines,
number of words and no. of character.

import os
You're Reading a Preview
lines = 0 Upload your documents to download.
words = 0

letters = 0
Upload to Download
filesize = 0

for line in open("Mydoc.txt"):

lines += 1 OR
letters += len(line)

# get the size of file


Become a Scribd member to read and download full
filesize = os.path.getsize("Mydoc.txt")
documents.
# A flag that signals the location outside the word.

pos = 'out'
Start your 30 day free trial
for letter in line:

if letter != ' ' and pos == 'out':

words += 1

pos = 'in'

elif letter == ' ':

pos = 'out'

print("Size of File is",filesize,'bytes')

print("Lines:", lines)

print("Words:", words)

print("Letters:", letters)
Page 20 of 45

Ad Download to read ad-free

Practical No-11

# Create a binary file with the name and roll number. Search for a given roll
number and display the name, if not found display appropriate message.

import pickle
You're Reading a Preview
Upload your documents to download.
def Writerecord(sroll,sname):

with open ('StudentRecord1.dat','ab') as Myfile:


Upload to Download
srecord={"SROLL":sroll,"SNAME":sname}

pickle.dump(srecord,Myfile)

OR
def Readrecord():

with open ('StudentRecord1.dat','rb') as Myfile:


Become a Scribd member to read and download full
print("\n-------DISPALY STUDENTS DETAILS--------")
documents.
print("\nRoll No.",' ','Name','\t',end='')

print()
Start your 30 day free trial
while True:

try:

rec=pickle.load(Myfile)

print(' ',rec['SROLL'],'\t ' ,rec['SNAME'])

except EOFError:

break

def Input():

n=int(input("How many records you want to create :"))

for ctr in range(n):

sroll=int(input("Enter Roll No: "))


Page 21 of 45

Ad Download to read ad-free

sname=input("Enter Name: ")

Writerecord(sroll,sname)

You're Reading a Preview


def SearchRecord(roll):

with openUpload your documents


('StudentRecord1.dat','rb') as Myfile:to download.
while True:

try: Upload to Download


rec=pickle.load(Myfile)

if rec['SROLL']==roll:
OR
print("Roll NO:",rec['SROLL'])

print("Name:",rec['SNAME'])

Become a Scribd member to read and download full


except EOFError:
documents.
print("Record not find..............")

Start your 30 day


print("Try Again..............") free trial
break

def main():

while True:

print('\nYour Choices are: ')

print('1.Insert Records')

print('2.Dispaly Records')

print('3.Search Records (By Roll No)')

Page 22 of 45

Ad Download to read ad-free

print('0.Exit (Enter 0 to exit)')

ch=int(input('Enter Your Choice: '))

if ch==1:
You're Reading a Preview
Input()
Upload
elif ch==2: your documents to download.
Readrecord()

elif ch==3: Upload to Download


r=int(input("Enter a Rollno to be Search: "))

SearchRecord(r)

else: OR
break

Become a Scribd
main() member to read and download full
documents.

Start your 30 day free trial

Page 23 of 45

Ad Download to read ad-free

Practical No-12

# Create a binary file with roll number, name and marks. Input a roll number
and update details. Create a binary file with roll number, name and marks.
You're Reading a Preview
Input a roll number and update details.

def Writerecord(sroll,sname,sperc,sremark):
Upload your documents to download.
with open ('StudentRecord.dat','ab') as Myfile:

srecord={"SROLL":sroll,"SNAME":sname,"SPERC":sperc,
Upload to Download
"SREMARKS":sremark}

pickle.dump(srecord,Myfile)

def Readrecord():
OR
with open ('StudentRecord.dat','rb') as Myfile:

print("\n-------DISPALY STUDENTS DETAILS--------")


Become a Scribd member to read and download full
print("\nRoll No.",' ','Name','\t',end='')
documents.
print('Percetage',' ','Remarks')

while True:

try:
Start your 30 day free trial
rec=pickle.load(Myfile)

print(' ',rec['SROLL'],'\t ' ,rec['SNAME'],'\t ',end='')

print(rec['SPERC'],'\t ',rec['SREMARKS'])

except EOFError:

break

def Input():

n=int(input("How many records you want to create :"))

for ctr in range(n):

sroll=int(input("Enter Roll No: "))


Page 24 of 45

Ad Download to read ad-free

sname=input("Enter Name: ")

sperc=float(input("Enter Percentage: "))

You're Reading a Preview


sremark=input("Enter Remark: ")

Writerecord(sroll,sname,sperc,sremark)
Upload
def Modify(roll): your documents to download.
with open ('StudentRecord.dat','rb') as Myfile:

newRecord=[] Upload to Download


while True:

try:

rec=pickle.load(Myfile) OR
newRecord.append(rec)

Become a Scribd member to read and download full


except EOFError:

break
documents.
found=1

Start your 30 day


for i in range(len(newRecord)): free trial
if newRecord[i]['SROLL']==roll:

name=input("Enter Name: ")

perc=float(input("Enter Percentage: "))

remark=input("Enter Remark: ")

newRecord[i]['SNAME']=name

newRecord[i]['SPERC']=perc

newRecord[i]['SREMARKS']=remark

found =1

else:

Page 25 of 45

Ad Download to read ad-free

found=0

if found==0:

You're Reading a Preview


print("Record not found")

with open ('StudentRecord.dat','wb') as Myfile:


Upload your
for j in newRecord: documents to download.
pickle.dump(j,Myfile)

def main(): Upload to Download


while True:

print('\nYour Choices are: ')

print('1.Insert Records') OR
print('2.Dispaly Records')

Become a Scribd
print('3.Update member to read and download full
Records')

documents.
print('0.Exit (Enter 0 to exit)')

ch=int(input('Enter Your Choice: '))

if ch==1: Start your 30 day free trial


Input()

elif ch==2:

Readrecord()

elif ch==3:

r =int(input("Enter a Rollno to be update: "))

Modify(r)

else:

break

main()

Page 26 of 45

Ad Download to read ad-free

Practical No-13

# Write a program to perform read and write operation onto a student.csv file
having fields as roll number, name, stream and percentage.

import csv
You're Reading a Preview
Upload your documentsasto
with open('Student_Details.csv','w',newline='') download.
csvf:

writecsv=csv.writer(csvf,delimiter=',')

choice='y'
Upload to Download
while choice.lower()=='y':

rl=int(input("Enter Roll No.: "))

n=input("Enter Name: ") OR


p=float(input("Enter Percentage: "))

r=input("Enter Remarks: ")


Become a Scribd member to read and download full
writecsv.writerow([rl,n,p,r])
documents.
print(" Data saved in Student Details file..")

choice=input("Want add more record(y/n).....")


Start your 30 day free trial

with open('Student_Details.csv','r',newline='') as fileobject:

readcsv=csv.reader(fileobject)

for i in readcsv:

print(i)

Page 27 of 45

Ad Download to read ad-free

Practical No-14

# Write a program to create a library in python and import it in a program.

You're Reading a Preview


#Let's create a package named Mypackage, using the following steps:

#• Create a new folder named NewApp in D drive (D:\NewApp)


Upload your documents to download.
#• Inside NewApp, create a subfolder with the name 'Mypackage'.

#• Create an empty __init__.py file in the Mypackage folder

Upload to Download
#• Create modules Area.py and Calculator.py in Mypackage folder with
following code

# Area.py Module OR
import math

def rectangle(s1,s2):
Become a Scribd member to read and download full
area = s1*s2
documents.
return area

Start your 30 day free trial


def circle(r):

area= math.pi*r*r

return area

def square(s1):

area = s1*s1

return area

def triangle(s1,s2):

area=0.5*s1*s2
Page 28 of 45

Ad Download to read ad-free

return area

# Calculator.py Module

def sum(n1,n2):
You're Reading a Preview
s = n1 + n2

return s Upload your documents to download.


def sub(n1,n2):

r = n1 - n2 Upload to Download
return r

def mult(n1,n2):

m = n1*n1 OR
return m

Become
def div(n1,n2):a Scribd member to read and download full
d=n1/n2
documents.
return d

# main() function Start your 30 day free trial


from Mypackage import Area

from Mypackage import Calculator

def main():

r = float(input("Enter Radius: "))

area =Area.circle(r)

print("The Area of Circle is:",area)

s1 = float(input("Enter side1 of rectangle: "))

s2 = float(input("Enter side2 of rectangle: "))

area = Area.rectangle(s1,s2)

Page 29 of 45

Ad Download to read ad-free

print("The Area of Rectangle is:",area)

s1 = float(input("Enter side1 of triangle: "))

You're Reading a Preview


s2 = float(input("Enter side2 of triangle: "))

area = Area.triangle(s1,s2)

print("TheUpload your documents


Area of TriRectangle is:",area) to download.
s = float(input("Enter side of square: "))

area =Area.square(s) Upload to Download


print("The Area of square is:",area)

num1 = float(input("\nEnter First number :"))

num2 = float(input("\nEnter secondOR


number :"))

print("\nThe Sum is : ",Calculator.sum(num1,num2))

Become
print("\nTheaMultiplication
Scribd member to read and download full
is : ",Calculator.mult(num1,num2))

documents.
print("\nThe sub is : ",Calculator.sub(num1,num2))

print("\nThe Division is : ",Calculator.div(num1,num2))

main() Start your 30 day free trial

Page 30 of 45

Ad Download to read ad-free

Practical No-15

# Take a sample of ten phishing e-mails (or any text file) and find the most
commonly occurring word(s).

def Read_Email_File():
You're Reading a Preview
Upload
import collections your documents to download.
fin = open('email.txt','r')

a= fin.read()
Upload to Download
d={ }

L=a.lower().split()

for word in L: OR
word = word.replace(".","")

word = word.replace(",","")
Become a Scribd member to read and download full
word = word.replace(":","")
documents.
word = word.replace("\"","")

word = word.replace("!","")
Start your 30 day free trial
word = word.replace("&","")

word = word.replace("*","")

for k in L:

key=k

if key not in d:

count=L.count(key)

d[key]=count

n = int(input("How many most common words to print: "))

print("\nOK. The {} most common words are as follows\n".format(n))

word_counter = collections.Counter(d)
Page 31 of 45

Ad Download to read ad-free

for word, count in word_counter.most_common(n):

print(word, ": ", count)

fin.close()
You're Reading a Preview
#Driver CodeUpload your documents to download.
def main():

Read_Email_File() Upload to Download


main()

OR

Become a Scribd member to read and download full


documents.

Start your 30 day free trial

Page 32 of 45

Ad Download to read ad-free

Practical No-16

# Write a python program to implement a stack using a list data-structure.

def isempty(stk):
You're Reading a Preview
if stk==[]:
Upload
return True your documents to download.
else:

return False Upload to Download

def push(stk,item):

stk.append(item) OR
top=len(stk)-1

Become a Scribd member to read and download full


def pop(stk):
documents.
if isempty(stk):

Start
return "underflow" your 30 day free trial
else:

item=stk.pop()

if len(stk)==0:

top=None

else:

top=len(stk)-1

return item

def peek(stk):

Page 33 of 45

Ad Download to read ad-free

if isempty(stk):

return "underflow"

else:
You're Reading a Preview
top=len(stk)-1
Upload
return stk[top] your documents to download.

def display(stk): Upload to Download


if isempty(stk):

print('stack is empty')

else: OR
top=len(stk)-1

Become a Scribd member to read and download full


print(stk[top],'<-top')

for i in range(top-1,-1,-1):
documents.
print(stk[i])

Start your 30 day free trial


#Driver Code

def main():

stk=[]

top=None

while True:

print('''stack operation

1.push

2.pop

Page 34 of 45

Ad Download to read ad-free

3.peek
4.display
5.exit''')
You're Reading a Preview
choice=int (input('enter choice:'))

Upload your documents to download.


if choice==1:
item=int(input('enter item:'))
push(stk,item)
elif choice==2: Upload to Download
item=pop(stk)
if item=="underflow":
print('stack is underflow') OR
else:

Become a Scribd member to read and download full


print('poped')
elif choice==3:
documents.
item=peek(stk)
if item=="underflow":
Start your 30 day free trial
print('stack is underflow')
else:
print('top most item is:',item)
elif choice==4:
display(stk)
elif choice==5:
break
else:
print('invalid')
exit()
main()
Page 35 of 45

Ad Download to read ad-free

Practical No-17

# Write a program to implement a queue using a list data structure.

You're Reading a Preview


# Function to check Queue is empty or not
Upload
def isEmpty(qLst): your documents to download.
if len(qLst)==0:

return 1 Upload to Download


else:

return 0
OR

# Become a Scribd
Function to add elementsmember
in Queue to read and download full
def Enqueue(qLst,val):
documents.
qLst.append(val)

if len(qLst)==1: Start your 30 day free trial


front=rear=0

else:

rear=len(qLst)-1

# Function to Delete elements in Queue

def Dqueue(qLst):

if isEmpty(qLst):

return "UnderFlow"

else:

Page 36 of 45

Ad Download to read ad-free

val = qLst.pop(0)

if len(qLst)==0:

front=rear=None
You're Reading a Preview
return val
Upload your documents to download.
# Function to Display top element of Queue

def Peek(qLst): Upload to Download


if isEmpty(qLst):

return "UnderFlow"

else: OR
front=0

Become a Scribd member to read and download full


return qLst[front]

documents.
# Function to Display elements of Queue

def Display(qLst): Start your 30 day free trial


if isEmpty(qLst):

print("No Item to Dispay in Queue....")

else:

tp = len(qLst)-1

print("[FRONT]",end=' ')

front = 0

i = front

rear = len(qLst)-1

while(i<=rear):

Page 37 of 45

Ad Download to read ad-free

print(qLst[i],'<-',end=' ')

i += 1

print()
You're Reading a Preview
Upload your documents to download.
# Driver function

def main(): Upload to Download


qList = []

front = rear = 0

while True: OR
print()

Become a Scribd
print("##### member#####")
QUEUE OPERATION to read and download full
print("1. ENQUEUE ")
documents.
print("2. DEQUEUE ")

Start
print("3. PEEK ") your 30 day free trial
print("4. DISPLAY ")

print("0. EXIT ")

choice = int(input("Enter Your Choice: "))

if choice == 1:

ele = int(input("Enter element to insert"))

Enqueue(qList,ele)

elif choice == 2:

val = Dqueue(qList)

if val == "UnderFlow":

Page 38 of 45

Ad Download to read ad-free

print("Queue is Empty")

else:

You're Reading a Preview


print("\n Deleted Element was : ",val)

Upload
elif choice==3: your documents to download.
val = Peek(qList)

Upload to
if val == "UnderFlow": Download
print("Queue is Empty")

else:

print("Item at Front: ",val) OR

Become a Scribd member to read and download full


elif choice==4:

Display(qList)
documents.
elif choice==0:

print("Good Start your 30 day


Luck......") free trial
break

main()

Page 39 of 45

Ad Download to read ad-free

Practical No-18

SQL

You're Reading a Preview


Create a table EMPLOYEE with constraints

SOLUTION
Upload your documents to download.
Step-1 Create a database:

CREATE DATABASE Bank;

Upload to
Step-2 Display the databases Download
SHOW DATABASES;

Step-3: Enter into database

Use Bank;
OR
Step-4: Create the table EMPLOYEE
Become
create a Scribd member
table Employee(Ecode int primaryto read and
key,Ename download
varchar(20) full
NOT NULL,

documents.
Dept varchar(15),City varchar(15), sex char(1), DOB date, Salary float(12,2));

Start
Insert data into the table your 30 day free trial
SOLUTION

insert into Employee values(1001,"Atul","Production","Vadodara","M","1992-

10-23",23000.50);

Query OK, 1 row affected (0.11 sec)

Note: Insert more rows as per above insert command.

Add a new column in a table.

SOLUTION

ALTER TABLE EMPLOYEE ADD address varchar(50);

Page 40 of 45

Ad Download to read ad-free

Change the data-type and size of an existing column.

SOLUTION

You're Reading a Preview


ALTER TABLE EMPLOYEE MODIFY city char(30);

Write SQL queries using SELECT, FROM, WHERE clause based on


Upload
EMPLOYEE table. your documents to download.
1. List the name of female employees in EMPLOYEE table.

Solution:- Upload to Download


SELECT Ename FROM EMPLOYEE WHERE sex=’F’;

2. Display the name and department of those employees who work in surat

and salary is greater than 25000. OR


Solution:-

Become
SELECT Ename,aDept
Scribd
FROMmember to read
EMPLOYEE WHERE and download
city=’surat’ full
and salary > 25000;

documents.
3. Display the name of those female employees who work in Mumbai.

Solution:-

SELECT Ename FROMStart your


EMPLOYEE 30 day
WHERE sex=’F’free trial
and city=’Mumbai’;

4. Display the name of those employees whose department is marketing or

RND.

Solution:-

SELECT Ename FROM EMPLOYEE WHERE Dept=’marketing’ OR Dept=’RND’

5. List the name of employees who are not males.

Solution:-

SELECT Ename, Sex FROM EMPLOYEE WHERE sex!=’M’;

Page 41 of 45

Ad Download to read ad-free

Queries using DISTINCT, BETWEEN, IN, LIKE, IS NULL, ORDER BY,

GROUP BY, HAVING

You're Reading a Preview


A. Display the name of departments. Each department should be displayed
once.

SOLUTION Upload your documents to download.


SELECT DISTINCT(Dept) FROM EMPLOYEE;

B. Find the name and salary of those employees whose salary is between
35000 and 40000.
Upload to Download
SOLUTION

SELECT Ename, salary FROM EMPLOYEE WHERE salary BETWEEN 35000 and
40000;
OR
C. Find the name of those employees who live in guwahati, surat or jaipur city.
Become
SOLUTION a Scribd member to read and download full
documents.
SELECT Ename, city FROM EMPLOYEE WHERE city IN(‘Guwahati’,’Surat’,’Jaipur’);

D. Display the name of those employees whose name starts with ‘M’.

SOLUTION Start your 30 day free trial


SELECT Ename FROM EMPLOYEE WHERE Ename LIKE ‘M%’;

E. List the name of employees not assigned to any department.

SOLUTION

SELECT Ename FROM EMPLOYEE WHERE Dept IS NULL;

F. Display the list of employees in descending order of employee code.

SOLUTION

SELECT * FROM EMPLOYEE ORDER BY ecode DESC;

Page 42 of 45

Ad Download to read ad-free

G. Find the average salary at each department.

SOLUTION

You're Reading a Preview


SELECT Dept, avg(salary) FROM EMPLOYEE group by Dept;

H.Find maximum salary of each department and display the name of that

departmentUpload your documents


which has maximum to 39000.
salary more than download.
SOLUTION

SELECT Dept, max(salary)Upload to Download


FROM EMPLOYEE group by Dept HAVING
max(salary)>39000;

Queries for Aggregate functions- SUM( ), AVG( ), MIN( ), MAX( ), COUNT( )

OR in employee table.
a. Find the average salary of the employees

Solution:-

SELECT avg(salary) FROM EMPLOYEE;


Become a Scribd member to read and download full
b. Find the minimum salary of a female employee in EMPLOYEE table.
documents.
Solution:-

SELECT Ename, min(salary) FROM EMPLOYEE WHERE sex=’F’;


Start your 30 day free trial
c. Find the maximum salary of a male employee in EMPLOYEE table.

Solution:-

SELECT Ename, max(salary) FROM EMPLOYEE WHERE sex=’M’;

d. Find the total salary of those employees who work in Guwahati city.

Solution:-

SELECT sum(salary) FROM EMPLOYEE WHERE city=’Guwahati’;

e. Find the number of tuples in the EMPLOYEE relation.

Solution:- SELECT count(*) FROM EMPLOYEE

Page 43 of 45

Ad Download to read ad-free

Practical No-19

# Write a program to connect Python with MySQL using database connectivity


and perform the following operations on data in database: Fetch, Update and
delete the data. You're Reading a Preview
A. CREATE A TABLE
Upload your documents to download.
SOLUTION

import mysql.connector
Upload to Download
demodb = mysql.connector.connect(host="localhost", user="root",

passwd="computer", database="EDUCATION")

democursor=demodb.cursor( )
OR
democursor.execute("CREATE TABLE STUDENT (admn_no int primary key,

sname varchar(30), gender char(1), DOB date, stream varchar(15), marks


Become a Scribd member to read and download full
float(4,2))")

B. INSERT THE DATA documents.


SOLUTION

import mysql.connector
Start your 30 day free trial
demodb = mysql.connector.connect(host="localhost", user="root",

passwd="computer", database="EDUCATION")

democursor=demodb.cursor( )

democursor.execute("insert into student values (%s, %s, %s, %s, %s, %s)",

(1245, 'Arush', 'M', '2003-10-04', 'science', 67.34))

demodb.commit( )

C. FETCH THE DATA

SOLUTION

import mysql.connector
Page 44 of 45

Ad Download to read ad-free

demodb = mysql.connector.connect(host="localhost", user="root",

passwd="computer", database="EDUCATION")

democursor=demodb.cursor( )
You're Reading a Preview
democursor.execute("select * from student")
Upload
for i in democursor: your documents to download.
print(i)

D. UPDATE THE RECORDUpload to Download


SOLUTION

import mysql.connector
OR
demodb = mysql.connector.connect(host="localhost", user="root",

passwd="computer", database="EDUCATION")

Become a Scribd member


democursor=demodb.cursor( ) to read and download full
documents.
democursor.execute("update student set marks=55.68 where admn_no=1356")

demodb.commit( )

E. DELETE THE DATAStart your 30 day free trial


SOLUTION

import mysql.connector

demodb = mysql.connector.connect(host="localhost", user="root",

passwd="computer", database="EDUCATION")

democursor=demodb.cursor( )

democursor.execute("delete from student where admn_no=1356")

demodb.commit()

Page 45 of 45

Reward Your Curiosity


Everything you want to read.
Anytime. Anywhere. Any device.

Read For Free

Cancel Anytime

Read this document in other languages


Español

Share this document


    

You might also like

Document 38 pages

Class 12 Ip Practical Programs


2023-24 (Updated)
Jeet Tiwari
88% (25)

Document 22 pages

IP Practical File 2024-25


hellokripapatel23
100% (1)

Document 53 pages

CLASS 12 Computer Science


Practical - Report Files 2023 2024
malathi
100% (1)

Document 32 pages

Class 12 Computer Science


Project Python
Prakhar P.
74% (80)

Document 3 pages

Zadig 2.4 - USB Driver


Installation Made Easy
Jairo Andrés Valencia
0% (1)

Document 28 pages

Most Expected 2 Marks Most


Expected Questions Stack…
sridharan.sri7766
100% (1)

Document 8 pages

20 Python Programs
uplifter40
100% (3)

Document 36 pages

School Management
Agrim Agarwal
100% (3)

Document 43 pages

Class 12 Cs Practical Exercises


2023-2024 (Updated)
Jeet Tiwari
86% (14)

Document 31 pages

CH 2 - Revision Tour 2 - Practice


Material For Board Exam
Muhammed Nehan
100% (1)

Document 7 pages

Binary File Questions


Namita Sahu
No ratings yet

Document 77 pages

ISC Class XII Computer Science


Project JAVA Programs
Ted
68% (141)

Show more

About Suppor t

About Scribd Help / FAQ

Everand: Ebooks & Accessibility


Audiobooks
Purchase help
SlideShare
AdChoices
Press

Join our team! Social


Contact us Instagram
Invite friends Twitter
We and our 10 partners store and access information on your device
for personalized ads and content. Personal data may be processed,
Facebook
Legal
such as cookie identifiers, unique device identifiers, and browser
Pinterest
information. Third parties may store and access information on your
Termsand process this personal data. You may change or withdraw
device
your preferences by clicking on the cookie icon or link; however, as a
Privacy
consequence, you may not see relevant ads or personalized content.
Our website may use these cookies to:
Copyright
Measure the audience of the advertising on our website,
Cookie
without Preferences
profiling
Display personalized ads based on your navigation and your
Do not sell or share my
profile
personal information
Personalize our editorial content based on your navigation
Allow you to share content on social networks or platforms
Get ouronfr
present eewebsite
our apps
Send you advertising based on your location

Privacy Policy
Third Parties

Storage
Documents

Targeted Advertising
Language: English

Personalization
Copyright © 2024 Scribd Inc.

Analytics

Manage Preferences

Accept All

Reject All

You might also like