0% found this document useful (0 votes)
4 views

COMPUTER SCIENCE PRACTICAL FILE

This document is a practical file for a computer science course, detailing various programming tasks and exercises. It includes codes and outputs for functions related to prime checking, Fibonacci series, file handling (text, binary, CSV), and stack operations. The document serves as a comprehensive guide for students to implement and understand different programming concepts in Python.

Uploaded by

parth28malhotra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

COMPUTER SCIENCE PRACTICAL FILE

This document is a practical file for a computer science course, detailing various programming tasks and exercises. It includes codes and outputs for functions related to prime checking, Fibonacci series, file handling (text, binary, CSV), and stack operations. The document serves as a comprehensive guide for students to implement and understand different programming concepts in Python.

Uploaded by

parth28malhotra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

COMPUTER SCIENCE

PRACTICAL FILE

NAME-:ASHMITA GOYAL
CLASS-:12-B
ROLL NO.-:08
INDEX
Functions:
1. Code to check whether given no. is prime or not
2. Code to find sum of fibonacci series
3. Code to check whether given no. is armstrong or not
4. Code to count alphabet, spl. Characters and digits in string
5. Code to convert uppercase to lowercase letters
6. Code to count no. of words in string
7. Code to check whether given element exists in string or not
Text file:
1. Program to open a text file “STORY.TXT” in read mode and display
all contents on the output screen
2. Program to count the number of alphabets in the file
“STORY.TXT”.
3. Program to count no. of vowels in the text file “STORY.TXT”.
4. Program to display words beginning with ‘s’ in the text file
“STORY.TXT”.
Binary file:
1. Write a program to create the following functions and implement all
the functions:-
i)write a function writeemp()-to store an employee info to the file
ii)write a function reademp()-to read and display all the employee
info on the output screen
iii)write a function searchemp()-to display the employees who all are
getting salaries between 10000-17000
iv)write a function searchdept(dept)-to display all the employees
info who all are working under dept variable
2. Write a program to implement following functions
i) input n students information and store this information in
student.dat
ii) read the file and display the information from the file on the
output screen
iii)check whether the given roll no. exist in the file or not
iv)remove a record from the file student.dat
v)increase the fees of each student by ₹1000 of each student if
the fees is less than ₹40000 by using tell and seek function
Csv file:
1. Write a Program in Python that defines and calls the following user
defined functions:
(i) ADD() – To accept and add data of an employee to a CSV file
‘record.csv’. Each record consists of a list with field elements as
empid, name and mobile to store employee id, employee name and
employee salary respectively.
(ii) COUNTR() – To count the number of records present in the CSV
file named ‘record.csv’.

2. Write a program in python that defines and calls the following user defined
functions:

(i) add() – to accept and add data of an employee to a csv file ‘furdata.csv’.
each record consists of a list with field elements as fid, fname and fprice to
store furniture id, furniture name and furniture price respectively.

(ii) search()- to display the records of the furniture whose price is more than
10000.
Stack programs:
1. Write a function in Python
i)PUSH_EMP(Stack, EMP_list) to push records of those employees
whose deptno is either 333 or 444 containing in a EMP_list passed
as an argument
iii)return the current position of Top.
ii)POP_EMP(Stack) to remove a data from a stack and print the
deleted data
iii)return the current position of Top.
Note:- Push the data by considering the structure of Emo_list.
EMP_list-[[333, "Anil"],[111, "Amit"],[444, "Neha"]...........[999,
N]]
2. A list contains following record-[customer name,customer phone
no., city]
Write program to implement following codes:
i)push()-push an object containing name and phone number of the
customers who live in delhi
ii) pop()- pop the obj through the stack and display it also display
stack empty when there are no element in the stack
3. Program to push pop and display the elements from the stack
4. Write a program display the vowels present in the words entered
by the user
PYTHON PROGRAMS
1.FUNCTIONS PROGRAMS
QUES 1. WRITE A CODE TO CHECK WHETHER THE GIVEN PROGRAM IS PRIME OR NOT
CODE-:

OUTPUT-:

QUES 2. WRITE A CODE TO FIND SUM OF FIBONACCI SERIES


CODE-:

OUTPUT-:
QUES 3. TO CHECK WHETHER A NUMBER IS ARMSTRONG OR NOT
CODE-:

OUTPUT-:

QUES 4. CODE TO CHECK ALPHABETS , LETTERS AND SPECIAL CHARACTERS IN THE


STRING
CODE-:

OUTPUT-:
QUES 5. CODE TO CONVERT UPPERCASE LETTERS TO LOWERCASE LETTERS
CODE-:

OUTPUT-:

QUES 6. CODE TO COUNT NUMBER OF WORDS IN STRING


CODE-:

OUTPUT-:

QUES 7- CODE TO CHECK WHETHER GIVEN ELEMENT EXIST OR NOT


CODE-:

OUTPUT-:
2. TEXT FILE PROGRAMS
QUES 1.Program to create a text file “story.TXT”
Code:-

Output:-

QUES 2.Program to open a text file “story.TXT” in read mode and display all contents
on the output screen
Code:-

Output:-
QUES 3. Program to count the number of alphabets in the file “story.TXT”.
Code:-

Output:-

QUES 4. Program to count no. of vowels in the text file “story.TXT”.


Code:-

Output:-

QUES 5. Program to display words beginning with ‘s’ in the text file “story.TXT”.
Code:-

Output:-
3.BINARY FILE PROGRAMS
Ques1.Write a program to create the following functions and implement all the
functions:-
i)write a function writeemp()-to store an employee info to the file
ii)write a function reademp()-to read and display all the employee info on the output
screen
iii)write a function searchemp()-to display the employees who all are getting salaries
between 10000-17000
iv)write a function searchdept(dept)-to display all the employees info who all are
working under dept variable
i)Code:-

Output:-
ii) Code:-

Output:-

iii)Code:-

Output:-
iv)Code:-

Output:-

Ques2. Write a program to


i) input n students information and store this information in student.dat
ii) read the file and display the information from the file on the output screen
iii)check whether the given roll no. exist in the file or not
iv)remove a record from the file student.dat
v)increase the fees of each student by ₹1000 of each student if the fees is less than
₹40000 by using tell and seek function
i)Code:-

Output:-
ii) code:-
def readfile():
f=open ("student.dat","rb")
d={}
f=False
try:
while True:
d=pickel.load(f)
print("roll no.=",d["roll no."])
print("name=",d["name"])
print("fees=",d["fees"])
f=True
except:
if f==False:
print("end")
f.close()
readfile()
Output:-
end
Traceback (most recent call last):
File "C:/Users/HP USER/Documents/binary.py", line 17, in <module>
readfile()
File "C:/Users/HP USER/Documents/binary.py", line 16, in readfile
f.close()
AttributeError: 'bool' object has no attribute 'close'
iii) code:-

Output:-

iv) code:-

Output:-
v) code:-
import pickle
def increase():
f=open("student.dat","rb+")
d={}
a=False
try:
while True:
loc=f.tell()
d=pickle.load(f)
if d[2]<=40000:
d[2]+=1000
f.seek(loc,0)
pickle.dump(d,f)
print (d)
except:
if a==False:
print("not exist")
else:
print ("information updated")

f.close()
increase()
4. CSV FILE PROGRAMS
QUES 1. WRITE A PROGRAM IN PYTHON THAT DEFINES AND CALLS THE
FOLLOWING USER DEFINED FUNCTIONS:
(I) ADD() – TO ACCEPT AND ADD DATA OF EMPLOYEES TO A CSV FILE
‘RECORD.CSV’. EACH RECORD CONSISTS OF A LIST WITH FIELD ELEMENTS
AS EMPID, NAME AND EMPSALARY TO STORE EMPLOYEE ID, EMPLOYEE
NAME AND EMPLOYEE SALARY RESPECTIVELY.
(II) COUNTR() – TO COUNT THE NUMBER OF RECORDS PRESENT IN THE CSV
FILE NAMED ‘RECORD.CSV’.
CODE-:

OUTPUT-:
QUES 2. WRITE A PROGRAM IN PYTHON THAT DEFINES AND CALLS THE
FOLLOWING USER DEFINED FUNCTIONS:
(I) ADD() – TO ACCEPT AND ADD DATA OF AN EMPLOYEE TO A CSV FILE
‘FURDATA.CSV’. EACH RECORD CONSISTS OF A LIST WITH FIELD ELEMENTS
AS FID, FNAME AND FPRICE TO STORE FURNITURE ID, FURNITURE NAME AND
FURNITURE PRICE RESPECTIVELY.
(II) SEARCH()- TO DISPLAY THE RECORDS OF THE FURNITURE WHOSE PRICE
IS MORE THAN 10000.
Code:-

Output:-
5. STACK PROGRAMS
Ques1. Write a function in Python
i)PUSH_EMP(Stack, EMP_list) to push records of those employees whose deptno is
either 333 or 444 containing in a EMP_list passed as an argument
ii)POP_EMP(Stack) to remove a data from a stack and print the deleted data and return
the current position of Top.
Note:- Push the data by considering the structure of Emp_list.
EMP_list=[[333, "Anil"],[111, "Amit"],[444, "Neha"],[999, “N”]]
(i) Code:-

Output:-

ii) Code:-

Output:-
Ques2. A list contains following record-[customer name,customer phone no., city]
Write program to implement following codes:
i)push()-push an object containing name and phone number of the customers who live
in delhi
ii) pop()- pop the obj through the stack and display it also display stack empty when
there are no element in the stack
Code:-
status=[]
l=["a", 8765456767,"delhi"]
def push(l):
if l[2]=="delhi":
status.append(l[0],l[1])
def pop():
if status==[]:
print("stack underflow ")
else:
print ("deleted customer",status.pop())
push(l)
pop()

Ques3. Program to push pop and display the elements from the stack
Code:-
Output:-

Ques4. Program to display the vowels present in the words entered by the user
Code:-

Output:-

You might also like