Created on Aug 4 2025
"""
#CSV FILES
# write a record with student roll no, Name and marks
#in the csv file using writerow( ) function
'''
import csv
fh=open("[Link]","w",newline="")
stuwriter=[Link](fh) # stuwriter is the object of the [Link]( ) func
[Link](['ROLLNO','NAME','MARKS'])
rec=[]
while True:
print("Enter the student's record ")
r=int(input("Enter the rollno : "))
n=input("Enter the name : ")
m=int(input("Enter the marks : "))
sturec=[r,n,m]
[Link](sturec)
ch=input(" Do you want to enter more records ? (Y/N) ")
if ch in "Nn":
break
for i in rec: # to write records one by one
[Link](i)
[Link]()
#Reading from the csv file
fh=open("[Link]","r")
stureader=[Link](fh) # stureader is the object of the [Link]( ) func
for i in stureader: # to read records one by one
print(i)
[Link]()
'''
#WAP to write, read and search data from a CSV file
#csv file should contain itemno,itemname,quantity and price
import csv
def write():
f=open("[Link]","w",newline="")
swriter=[Link](f)
[Link](["INo","IName","Qty","Price"])
rec=[]
while True:
n=int(input("Item No : "))
name=input("Enter Item Name : ")
qty=int(input("Enter Quantity : "))
price=int(input("Enter Price : "))
data=[n,name,qty,price]
[Link](data)
ch=input(" Do you want to enter more records ? (Y/N) ")
if ch in "Nn":
break
[Link](rec)
print("Data written in csv file successfully : ")
[Link]()
def read():
f=open("[Link]","r")
sreader=[Link](f)
for i in sreader:
print(i)
[Link]()
def searchitmno():
f=open("[Link]","r")
print("Searching data from a csv file : ")
s=input("Enter the Item No to be searched : ")
found=0
sreader=[Link](f)
for i in sreader:
if i[0]==s:
print(i)
found=1
break
if found==0:
print("Sorry Record Not Found : ")
[Link]()
def searchitmname():
f=open("[Link]","r")
print("Searching data from a csv file : ")
s=input("Enter the Item Name to be searched : ")
found=0
sreader=[Link](f)
for i in sreader:
if i[1]==s:
print(i)
found=1
break
if found==0:
print("Sorry Record Not Found : ")
[Link]()
#write()
#read()
#searchitmno()
#searchitmname()
Write a Program in Python that defines and calls the following user defined functions:
(i) add() – To accept and add data of EMPLOYEE to a CSV file ‘[Link]’. Each record consists
of a list with field elements as empid, ename and esalary to store employee id, employee
name and employee salary respec- tively.
(ii) search()- To display the records of the employee whose salary is more than 10000.
(iii) display( ) – To display all the records that have salary less than 3000
def display():
with open(“[Link]”, “r”) as csvfile:
csvreader = [Link](csvfile)
for rows in csvreader:
if rows[2]<3000:
print(“workder id=”,rows[0])
print(“name=”,rows[1])
(i)def add():
with open(“[Link]”, “a”, newline=’’) as fhcsv:
csv_writer=[Link](fhcsv)
r=int(input(“enter [Link] :”))
n=input(“enter name :”)
m=int(input(“enter salary :”))
rec=[r,n,m]
csv_writer.writerow(rec)
(ii)def search():
with open(“[Link]”, “r”) as csvfile:
csvreader = [Link](csvfile)
for rows in csvreader:
if rows[2]>10000:
print(rows)