0% found this document useful (0 votes)
30 views21 pages

Finall Class 12th CS Practcal File by Manthan

Uploaded by

Aman Rai
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)
30 views21 pages

Finall Class 12th CS Practcal File by Manthan

Uploaded by

Aman Rai
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/ 21

Bloom International School

SESSION:-2022-2023

Computer Science
PRACTICAL FILE
(CODE-083)

Submitted to: Ms. Shilpa Garg


Submitted by: Manthan Bhardwaj
Class: 12th (Science)
CBSE Roll No:
Certificate

Roll No: Exam No:_______

This is to certify that Manthan Bhardwaj student of class 12th


has successfully completed the research on the below
mentioned project under the guidance of Ms. Shilpa Garg
during the year of 2022-23 in partial fulfillment of
computer science practical examination 083 conducted by
Bloom international school, Noida.
________________ _______________
SIGNATURE OF EXTERNAL SIGNATURE OF INTERNAL
EXAMINER EXAMINER

_____________
Principal
INDEX

Unit No Unit Name Marks Theory Practical

1 Computational Thinking and 40 70 50


Programming

2 Computer Networks 10 15 —

3 Database Management 20 25 20

Total 70 110 70
Practical

S.No Unit Name Marks


(Total=30)
1 Lab Test: 1. Python program (60% logic + 20% 8
documentation + 20% code quality)

2. A stub program with Python SQL connectivity must


be provided with blanks (4 blanks) to be filled by the
student with the desired SQL query.

2 Report file: 4
1. Minimum 15 Python programs.
2. SQL Queries – Minimum 5 sets using one table /
two tables.
3. Minimum 4 programs based on Python - SQL
connectivity

3 Project (using concepts learned in Classes 11 and 12) 7

4 Viva voce 3
Acknowledgement

In the accomplishment of this project successfully, many


people have best owned upon me their blessings and the
heart pledge support, this time I am utilizing to thank all
the people who have been concerned with this project.
Primarily I would like to thank god for being able to
complete this project with success. Then I would like to
thank my principal Smt. Shakuntala Rai and my Computer
science teacher Ms. Shilpa Garg whose valuable guidance
has been the ones that helped me patch this project and
make it a complete proof success, his suggestions and instruction
have served as a major contribution towards the
completion of this project.
Then I would like to thank my parents who have helped
me with their valuable suggestions and guidance has been
very helpful in various phases of the completion of the
project.
Source code

1. Read a text file line by line and display each word separated by a '#' in
Python

Procedure:
1. Open a file in read mode which contains a string.
2. Use for loop to read each line from the text file.
3. Again use for loop to read each word from the line splitted by ‘ ‘.
4. Display each word seperated by '#' from each line in the text file.

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

Or

Filein = open("mydoc.txt",'r')
line =" "
while line:
line = filein.readline()
#print(line)
for w in line:
if w == ' ':
print('#',end = '')
else:
print(w,end = '')
filein.close()

OUTPUT:-
Twinkle,#twinkle,#little#star,

How#I#wonder#what#you#are!

Up#above#the#world#so#high,

Like#a#diamond#in#the#sky.

When#the#blazing#sun#is#gone,

When#he#nothing#shines#upon,

Then#you#show#your#little#light,

Twinkle,#twinkle,#all#the#night.

2. Read a text file and display the number of


vowels/consonants/uppercase/lowercase characters in the file.

def cnt():
f=open("demo1.txt","r")
cont=f.read()
print(cnt)
v=0
cons=0
l_c_l=0
u_c_l=0
for ch in cont:
if (ch.islower()):
l_c_l+=1
elif(ch.isupper()):
u_c_l+=1
ch=ch.lower()
if( ch in ['a','e','i','o','u']):
v+=1
elif (ch in ['b','c','d','f','g',
'h','j','k','l','m',
'n','p','q','r','s',
't','v','w','x','y','z']):
cons+=1
f.close()
print("Vowels are : ",v)
print("consonants are : ",cons)
print("Lower case letters are : ",l_c_l)
print("Upper case letters are : ",u_c_l)
#main program
cnt()
OUTPUT:-

Vowels are : 64
consonants are : 118
Lower case letters are : 173
Upper case letters are : 9

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

Program Logic:
Open input file say ‘assignment.txt’ in read mode and store in temporary
file object
say ‘input_file’
Open output file say ‘dataoutput.txt’ in write mode and store in
temporary file object
say ‘output_file’
Read the contents of input file using readlines()
Iterate through input file using for loop
Within for loop, if statement is used to check input file contains the
character ‘a’ or
not
Write only those lines that does not contain character ‘a’ in output file
using write()
Close all input and output file

fo=open("hp.txt","w")

fo.write("Harry Potter")

fo.write("There is a difference in all harry potter books\nWe can see it


as

harry grows\nthe books were written by J.K rowling ")

fo.close()

fo=open('hp.txt','r')

fi=open('writehp.txt','w')

l=fo.readlines()

for i in l:

if 'a' in i:

i=i.replace('a','')

fi.write(i)

fi.close()

4. Create a binary file with roll number, name and marks. Input a roll
number and update the marks.
import pickle
#creating the file and writing the data
f=open("records.dat", "wb")
#list index 0 = roll number
#list index 1 = name
#list index 2 = marks
pickle.dump([1, "Wakil", 90], f)
pickle.dump([2, "Tanish", 80], f)
pickle.dump([3, "Priyashi", 90], f)
pickle.dump([4, "Kanupriya", 80], f)
pickle.dump([5, "Ashutosh", 85], f)
f.close()
#opeining the file to read contents
f=open("records.dat", "rb")
roll=int(input("Enter the Roll Number: "))
marks=float(input("Enter the updated marks: "))
List = [ ] #empty list
flag = False #turns to True if record is found
while True:
try:
record=pickle.load(f)
List.append(record)
except EOFError:
break
f.close()
#reopening the file to update the marks
f=open("records.dat", "wb")
for rec in List:
if rec[0]==roll:
rec[2] = marks
pickle.dump(rec, f)
print("Record updated successfully")
flag = True
else:
pickle.dump(rec,f)
f.close()
if flag==False:
print("This roll number does not exist")

5. Write a random number generator that generatesrandom numbers


between 1 and 6 (simulatesa dice).

def random():
import random
s=random.randint(1,6)
return s
print(random())

6. This is a Python program to implement a stack using a linked list.

Problem Description
The program creates a stack and allows the user to perform push and pop
operations on it.

Problem Solution
1. Create a class Node with instance variables data and next.
2. Create a class Stack with instance variable head.
3. The variable head points to the first element in the linked list.
4. Define methods push and pop inside the class Stack.
5. The method push adds a node at the front of the linked list.
6. The method pop returns the data of the node at the front of the linked
list and removes the node. It returns None if there are no nodes.

7. Create an instance of Stack and present a menu to the user to perform


operations on the stack.

class Node:
def __init__(self, data):
self.data = data
self.next = None

class Stack:
def __init__(self):
self.head = None

def push(self, data):


if self.head is None:
self.head = Node(data)
else:
new_node = Node(data)
new_node.next = self.head
self.head = new_node

def pop(self):
if self.head is None:
return None
else:
popped = self.head.data
self.head = self.head.next
return popped

a_stack = Stack()
while True:
print('push <value>')
print('pop')
print('quit')
do = input('What would you like to do? ').split()

operation = do[0].strip().lower()
if operation == 'push':
a_stack.push(int(do[1]))
elif operation == 'pop':
popped = a_stack.pop()
if popped is None:
print('Stack is empty.')
else:
print('Popped value: ', int(popped))
elif operation == 'quit':
break

8. Create a CSV file by entering user-id and password, read and search
the password for given user id.
import csv
with open("7.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
with open("7.csv", "r") as obj2:
fileobj2 = csv.reader(obj2)
given = input("enter the user id to be searched\n")

for i in fileobj2:
next(fileobj2)

# print(i,given)
if i[0] == given:
print(i[1])
break

9. Write a menu-driven python program to implement stack operation.


def check_stack_isEmpty(stk):
if stk==[]:
return True
else:
return False
s=[] # An empty list to store stack elements, initially its empty
top = None # This is top pointer for push and pop operation
def main_menu():
while True:
print("Stack Implementation")
print("1 - Push")
print("2 - Pop")
print("3 - Peek")
print("4 - Display")
print("5 - Exit")
ch = int(input("Enter the your choice:"))
if ch==1:
el = int(input("Enter the value to push an element:"))
push(s,el)
elif ch==2:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("Element popped:",e)
elif ch==3:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("The element on top is:",e)
elif ch==4:
display(s)
elif ch==5:
break
else:
print("Sorry, You have entered invalid option")
def push(stk,e):
stk.append(e)
top = len(stk)-1
def display(stk):
if check_stack_isEmpty(stk):
print("Stack is Empty")
else:
top = len(stk)-1
print(stk[top],"-Top")
for i in range(top-1,-1,-1):
print(stk[i])
def pop_stack(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
e = stk.pop()
if len(stk)==0:
top = None
else:
top = len(stk)-1
return e
def peek(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
top = len(stk)-1
return stk[top]

10. Write a program to implement a stack for the employee details


(empno, name).

stk=[]
top=-1
def line():
print('~'*100)

def isEmpty():
global stk
if stk==[]:
print("Stack is empty!!!")
else:
None
def push():
global stk
global top
empno=int(input("Enter the employee number to push:"))
ename=input("Enter the employee name to push:")
stk.append([empno,ename])
top=len(stk)-1

def display():
global stk
global top
if top==-1:
isEmpty()
else:
top=len(stk)-1
print(stk[top],"<-top")
for i in range(top-1,-1,-1):
print(stk[i])

def pop_ele():
global stk
global top
if top==-1:
isEmpty()
else:
stk.pop()
top=top-1

def main():
while True:
line()
print("1. Push")
print("2. Pop")
print("3. Display")
print("4. Exit")
ch=int(input("Enter your choice:"))
if ch==1:nm
push()
print("Element Pushed")
elif ch==2:
pop_ele()
elif ch==3:
display()
else:
print("Invalid Choice")

You might also like