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

Term 1 CS Practical File 2021-22

The document appears to be a student's practical record file submitted for a computer science course. It includes an acknowledgement section thanking teachers for their guidance. It also includes a certificate section signed by internal and external examiners and the principal certifying the completion of practical work. The main body consists of 15 programming problems completed by the student with details of each problem and the code written for it. Signatures of the teacher are included to verify completion of each practical.

Uploaded by

rana
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)
91 views

Term 1 CS Practical File 2021-22

The document appears to be a student's practical record file submitted for a computer science course. It includes an acknowledgement section thanking teachers for their guidance. It also includes a certificate section signed by internal and external examiners and the principal certifying the completion of practical work. The main body consists of 15 programming problems completed by the student with details of each problem and the code written for it. Signatures of the teacher are included to verify completion of each practical.

Uploaded by

rana
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/ 18

School &

CBSE
Logo

CENTRAL BOARD OF SECONDARY EDUCATION

School Name
Address

A TERM 1 PRACTICAL RECORD FILE IS SUBMITTED TO DEPARTMENT OF COMPUTER SCIENCE FOR


THE PARTIAL FULLFILLMENT OF AISSCE EXAMINATION SESSION - ________

SUBMITTED BY: [NAME OF STUDENT]


HOD(COMPUTER):[NAME OF SUBJECT TEACHER]
CLASS: [CLASS]
ROLL NO: [XXXXXXX]

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 1


CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 2
ACKNOWLEDGEMENT

I wish to express my deep sense of


gratitude and indebtedness to our learned teacher
TEACHER’S NAME , PGT COMPUTER SCIENCE,
[SCHOOL NAME] for his invaluable help, advice and
guidance in the preparation of this project.

I am also greatly indebted to our principal


[Name of principal] and school authorities for
providing me with the facilities and requisite
laboratory conditions for making this practical file.

I also extend my thanks to a number of


teachers ,my classmates and friends who helped me to
complete this practical file successfully.

[Name of Student]

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 3


CERTIFICATE

This is to certify that [Name of Student]

, student of Class XII, [NAME OF SCHOOL] has

completed the Term I - PRACTICAL FILE during the

academic year [SESSION] towards partial fulfillment

of credit for the Computer Science practical

evaluation of CBSE and submitted satisfactory report,

as compiled in the following pages, under my

supervision.

Total number of practical certified are : 15.

External Examiner Internal Examiner


Signature Signature

Head of the Department Principal


Signature Seal and Signature
CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 4
No. Practical Date Signature
Write a python program using a function to print factorial number series
1
from n to m numbers.
2 Write a python program to accept username "Admin" as default argument
and password 123 entered by user to allow login into the system.
3 Write a python program to demonstrate the concept of variable length
argument to calculate product and power of the first 10 numbers.
4 Create a text file "intro.txt" in python and ask the user to write a single line
text by user input.
5 Write a program to count a total number of lines and count the total number
of lines starting with 'A', 'B', and 'C' from the file dfh.txt.
6 Write a program to replace all spaces from text with – (dash) from the file
intro.txt.
7 Write a program to know the cursor position and print the text according to
below-given specifications:
1. Print the initial position
2. Move the cursor to 4th position
3. Display next 5 characters
4. Move the cursor to the next 10 characters
5. Print the current cursor position
6. Print next 10 characters from the current cursor position
8 Create a binary file client.dat to hold records like ClientID, Client name,
and Address using the list. Write functions to write data, read them, and
print on the screen.
9 Write a program to store customer data into a binary file cust.dat using a
dictionary and print them on screen after reading them. The customer data
contains ID as key, and name, city as values.
10 Write a program to create a binary file sales.dat and write a menu driven
program to do the following:

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 5


• Insert record
• Search Record
• Update Record
• Display record
• Exit
11 Write a function to write data into binary file marks.dat and display the
records of students who scored more than 95 marks.
12 Read a CSV file top5.csv and print the contents in a proper format. The
data for top5.csv file are as following:
Sno Batsman Team Runs Highest

1 K L Rahul KXI 670 132*

2 S Dhawan DC 618 106*

3 David Warner SRH 548 85*

4 Shreyas Iyer DC 519 88*

5 Ishan Kishan MI 516 99

13 Read a CSV file students.csv and print them with tab delimiter. Ignore first
row header to print in tabular form.
14 Write records of customer into result.csv. The fields are as following:
Field 1 Data Type

StudentID Integer

StudentName String

Score Integer

15 Count the number of records and column names present in the CSV file.
Concepts used:
1. Skip first row using next() method
2. line_num properties used to count the no. of rows

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 6


1. Write a python program using a function to print factorial number series from n to m numbers.
def facto():
n=int(input("Enter the number:"))
f=1
for i in range(1,n+1):
f*=i
print(f, end=" ")
facto()

2. Write a python program to accept username "Admin" as default argument and password 123
entered by user to allow login into the system.
def user_pass(password,username="Admin"):
if password=='123':
print("You have logged into system")
else:
print("Password is incorrect!!!!!!")
password=input("Enter the password:")
user_pass(password)

3. Write a python program to demonstrate the concept of variable length argument to calculate
product and power of the first 10 numbers.
def sum10(*n):
total=0
for i in n:
total=total + i
print("Sum of first 10 Numbers:",total)
sum10(1,2,3,4,5,6,7,8,9,10)
def product10(*n):
pr=1
for i in n:
pr=pr * i
print("Product of first 10 Numbers:",pr)
product10(1,2,3,4,5,6,7,8,9,10)

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 7


4. Create a text file "intro.txt" in python and ask the user to write a single line text by user input.

def program4():
f = open("intro.txt","w")
text=input("Enter the text:")
f.write(text)
f.close()
program4()

Input:

5. Write a program to count a total number of lines and count the total number of lines starting
with 'A', 'B', and 'C' from the file myfile.txt.
def program5():
with open("E:\\MyFile.txt","r") as f1:
data=f1.readlines()
cnt_lines=0
cnt_A=0
cnt_B=0
cnt_C=0
for lines in data:
cnt_lines+=1
if lines[0]=='A':
cnt_A+=1
if lines[0]=='B':
cnt_B+=1
if lines[0]=='C':
cnt_C+=1

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 8


print("Total Number of lines are:",cnt_lines)
print("Total Number of lines strating with A
are:",cnt_A)
print("Total Number of lines strating with B
are:",cnt_B)
print("Total Number of lines strating with C
are:",cnt_C)
program5()
File Content:
Python is super and trending language.
Allows to store the output in the files.
A text file stores textual data.
Binary files can handle binary data.
Binary files use pickle module to store data.
CSV files can handle tabular data.
CSV files can be read easily using CSV reader object.

6. Write a programto replace all spaces from text with - (dash) from the file intro.txt.
def program6():
cnt = 0
with open("intro.txt","r") as f1:
data = f1.read()
data=data.replace(' ','-')
with open("intro.txt","w") as f1:
f1.write(data)
with open("intro.txt","r") as f1:
print(f1.read())
program6()

7. Write a program to know the cursor position and print the text according to below-given
specifications:
a. Print the initial position
b. Move the cursor to 4th position
c. Display next 5 characters
d. Move the cursor to the next 10 characters
e. Print the current cursor position
f. Print next 10 characters from the current cursor position

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 9


def program7():
f = open("intro.txt","r")
print("Cusror initial position.")
print(f.tell())
f.seek(4,0)
print("Displaying values from 5th position.")
print(f.read(5))
f.seek(10,0)
print(f.tell())
print("Print cursor's current postion")
print(f.seek(7,0))
print("Displaying next 10 characters from cursor's
current postion.")
print(f.read(10))
program7()

8. Create a binary file client.dat to hold records like ClientID, Client name, and Address using the
dictionary. Write functions to write data, read them, and print on the screen.
import pickle
rec={}
def file_create():
f=open("client.dat","wb")
cno = int(input("Enter Client ID:"))
cname = input("Enter Client Name:")
address = input("Enter Address:")
rec={cno:[cname,address]}
pickle.dump(rec,f)
def read_data():
f = open("client.dat","rb")
print("*"*78)
print("Data stored in File....")
rec=pickle.load(f)
for i in rec:
print(rec[i])
file_create()
read_data()
CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 10
9. Write a program to create a binary file sales.dat and write a menu driven program to do the
following:
1. Insert record
2. Search Record
3. Update Record
4. Display record
5. Exit

import pickle
import os
def main_menu():
print("1. Insert a record")
print("2. Search a record")
print("3. Update a record")
print("4. Display a record")
print("5. Delete a record")
print("6. Exit")
ch = int(input("Enter your choice:"))
if ch==1:
insert_rec()
elif ch==2:
search_rec()
elif ch==3:
update_rec()
elif ch==4:
display_rec()
elif ch==5:
delete_rec()
elif ch==6:
print("Have a nice day!")
else:
print("Invalid Choice.")

def insert_rec():
f = open("sales.dat","ab")
c = 'yes'
while True:
sales_id=int(input("Enter ID:"))
name=input("Enter Name:")
city=input("Enter City:")

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 11


d =
{"SalesId":sales_id,"Name":name,"City":city}
pickle.dump(d,f)
print("Record Inserted.")
print("Want to insert more records, Type
yes:")
c = input()
c = c.lower()
if c not in 'yes':
break
main_menu()
f.close()

def display_rec():
f = open("sales.dat","rb")
try:
while True:
d = pickle.load(f)
print(d)
except Exception:
f.close()
main_menu()

def search_rec():
f = open("sales.dat","rb")
s=int(input("Enter id to search:"))
f1 = 0
try:
while True:
d = pickle.load(f)
if d["SalesId"]==s:
f1=1
print(d)
break
except Exception:
f.close()
if f1==0:
print("Record not found...")
else:
print("Record found...")
main_menu()

def update_rec():
f1 = open("sales.dat","rb")
f2 = open("temp.dat","wb")

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 12


s=int(input("Enter id to update:"))
try:
while True:
d = pickle.load(f1)
if d["SalesId"]==s:
d["Name"]=input("Enter Name:")
d["City"]=input("Enter City:")
pickle.dump(d,f2)
except EOFError:
print("Record Updated.")
f1.close()
f2.close()
os.remove("sales.dat")
os.rename("temp.dat","sales.dat")
main_menu()

def delete_rec():
f1 = open("sales.dat","rb")
f2 = open("temp.dat","wb")
s=int(input("Enter id to delete:"))
try:
while True:
d = pickle.load(f1)
if d["SalesId"]!=s:
pickle.dump(d,f2)
except EOFError:
print("Record Deleted.")
f1.close()
f2.close()
os.remove("sales.dat")
os.rename("temp.dat","sales.dat")
main_menu()
main_menu()

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 13


10. Write a function to write data into binary file marks.dat and display the records of students who
scored more than 95 marks.
import pickle
def search_95plus():
f = open("marks.dat","ab")
while True:
rn=int(input("Enter the rollno:"))
sname=input("Enter the name:")
marks=int(input("Enter the marks:"))
rec=[]
data=[rn,sname,marks]
rec.append(data)
pickle.dump(rec,f)
ch=input("Wnat more records?Yes:")
if ch.lower() not in 'yes':
break
f.close()
f = open("marks.dat","rb")
cnt=0
try:
while True:
data = pickle.load(f)

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 14


for s in data:
if s[2]>95:
cnt+=1
print("Record:",cnt)
print("RollNO:",s[0])
print("Name:",s[1])
print("Marks:",s[2])
except Exception:
f.close()
search_95plus()

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 15


11. Write a function to count records from the binary file marks.dat.
import pickle
def count_records():
f = open("marks.dat","rb")
cnt=0
try:
while True:
data = pickle.load(f)
for s in data:
cnt+=1
except Exception:
f.close()
print("The file has ", cnt, " records.")
count_records()

12. Read a CSV file top5.csv and print the contents in a proper format. The data for top5.csv file are as
following:
SNo Batsman Team Runs Highest
1 K L Rahul KXI 670 132*
2 S Dhawan DC 618 106*
3 David Warner SRH 548 85*
4 Shreyas Iyer DC 519 88*
5 Ishan Kishan MI 516 99
from csv import reader
def pro1():
with open("e:\\top5.csv","r") as f:
d = reader(f)
data=list(d)
for i in data:
print(i)
pro1()

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 16


13. Read a CSV file top5.csv and print them with tab delimiter. Ignore first row header to print in
tabular form.
from csv import reader
def pro13():
f = open("e:\\top5.csv","r")
dt = reader(f,delimiter=',')
headr_row=next(dt)
data = list(dt)
f.close()
for i in data:
for j in i:
print(j,"\t",end=" ")
print()
pro13()

14. Write records of students into result.csv. The fields are as following:
Field 1 Data Type
StudentID Integer
StudentName String
Score Integer
from csv import writer
def pro14():
#Create Header First
f = open("result.csv","w",newline='\n')
dt = writer(f)
dt.writerow(['Student_ID','StudentName','Score'])
f.close()
#Insert Data
f = open("result.csv","a",newline='\n')
while True:
st_id= int(input("Enter Student ID:"))
st_name = input("Enter Student name:")
st_score = input("Enter score:")
dt = writer(f)
dt.writerow([st_id,st_name,st_score])
ch=input("Want to insert More records?(y or
Y):")
ch=ch.lower()
if ch !='y':
break
print("Record has been added.")
f.close()
CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 17
15. Count the number of records and column names present in the CSV file.
Concepts used:
1. Skip first row using next() method
2. line_num properties used to count the no. of rows

import csv
def pro15():
fields = []
rows = []
with open('students.csv', newline='') as f:
data = csv.reader(f)
# Following command skips the first row of CSV file
fields = next(data)
print('Field names are:')
for field in fields:
print(field, "\t")
print()
print("Data of CSV File:")
for i in data:
print('\t'.join(i))
print("\nTotal no. of rows: %d"%(data.line_num))
pro15()

CS PRACTICAL RECORD FILE | Downloaded from www.tutorialaicsip.com | Page 18

You might also like