Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

What is the advantage of using a csv file for permanent storage?

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’.

 

Answer:

csv File

Binary File

Stores information in the form of a text file.

Stores information in the form of 0s and 1s.

Human readable

Not human readable

Extension is .csv

Extension is .dat

Code:

import csv

 

def add ():

    f=open( 'furdata.csv','a', newline= "\n" )

    write=csv.writer(f)

    fid=int(input( "Enter furniture id :: " ))

    fname=input( "Enter furniture name :: " )

    fprice=int(input( "Enter furniture price :: " ))

    list=[fid,fname,fprice]

    write.writerow(list)

    f.close()

 

def search ():

    f=open( "furdata.csv","r" ,newline= '\n' )

    records=csv.reader(f)

    flag=False

    print( "The Details of furnitures with price greater than 10,000: " )

    for r in records:

        if int(r[ 2 ])> 10000 :

            found=True

            print(r[ 0 ],r[1],r[2])

    if found==False:

        print( "Record not found" )

    f.close()

 

add()

add()

add()

search()

Class 12 - Sample Paper - Computer Science 2023.jpg

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo