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

All Programs 2024 to back 2021 CSV Qs

The document contains multiple Python functions for handling CSV files related to various entities such as devices, sports competitions, books, teachers, and employees. Each section includes functions to add, read, and count records based on specific criteria. The code demonstrates basic file operations using the CSV module in Python.

Uploaded by

roinowo9
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)
6 views

All Programs 2024 to back 2021 CSV Qs

The document contains multiple Python functions for handling CSV files related to various entities such as devices, sports competitions, books, teachers, and employees. Each section includes functions to add, read, and count records based on specific criteria. The code demonstrates basic file operations using the CSV module in Python.

Uploaded by

roinowo9
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/ 8

Subscribe for More

https://www.youtube.com/@TECHQueenLovejeetArora

import csv
def Write():
File=open('ok.csv','w',newline="")
WrObj=csv.writer(File)
while True:
p_id=int(input('Enter ID'))
p_name=input("Enter Name")
Price=int(input('Enter Price'))
List=[p_id,p_name,Price]
WrObj.writerow(List)
ch=input("Enter Y or y for more data")
if ch not in 'Yy':
break
File.close()
def Read():
File=open('ok.csv','r')
Data=csv.reader(File)
for i in Data:
print(i)
File.close()
def Add_Device():
File=open("ok.csv",'a',newline='')
WrObj=csv.writer(File)
ch=input("Do you want to add 1 more record in CSV press Y")
if ch in 'Yy':
p_id=int(input('Add New ID'))
p_name=input("Add New Name")
Price=int(input('Add New Price'))
List=[p_id,p_name,Price]
WrObj.writerow(List)
print("Data Added")
else:
return
File.close()
def Count_Device():
File=open("ok.csv",'r')
Data=csv.reader(File)
Count=0
next(Data)
for i in Data:
if int(i[2])>1000:
Count+=1
print("Display whose price is less than 1000-",Count)
File.close()
Count_Device()
Subscribe for More
https://www.youtube.com/@TECHQueenLovejeetArora

import csv
def Write():
File=open("ok.csv",'w',newline='')
WrObj=csv.writer(File)
WrObj.writerow(['SportsID','Competition','PrizeWon'])
while True:
sports_id=int(input("Enter sports ID"))
competition=input("Enter Competition Name")
Prize_won=input("Enter GOLD, SILVER, BRONZE")
List=[sports_id,competition,Prize_won]
WrObj.writerow(List)
ch=input("Enter choice - ")
if ch not in 'Yy':
break
File.close()
def Read():
File=open('ok.csv','r')
Data=csv.reader(File)
for i in Data:
print(i)
def Add_detail():
File=open("ok.csv",'a',newline='')
ObjWr=csv.writer(File)
Ch=input("Enter y for updation, Do you want to update data")
if Ch in 'Yy':
sports_id=int(input("New Enter sports ID"))
competition=input("New Enter Competition Name")
Prize_won=input("New Enter GOLD, SILVER, BRONZE")
List=[sports_id,competition,Prize_won]
ObjWr.writerow(List)
File.close()
def Count_Medal():
File=open('ok.csv','r')
Data=csv.reader(File)
next(Data)
for i in Data:
if i[2].lower() =='gold':
print("Gold Medal - :)", i)
File.close()
Write()
Read()
Add_detail()
Count_Medal()
Subscribe for More
https://www.youtube.com/@TECHQueenLovejeetArora

import csv
#cid,S_name,Source,Destination
#CourierId,SenderName,SOurrce,Destination
def Courier_Add():
File=open("Data.csv","w",newline="")
ObjWrite=csv.writer(File)
ObjWrite.writerow(["CourierId","SenderName","Source","Destination"])
while True:
cid=int(input("Enter Courier Id"))
S_Name=input("Enter S_Name")
Source=input("Enter Source")
Destination=input("Enter Destination")
List=[cid,S_Name,Source,Destination]
ObjWrite.writerow(List)
Ch=input("Enter Y or y for more Data")
if Ch not in "Yy":
break
File.close()
def Courier_Search():
File=open("Data.csv","r")
Data=csv.reader(File)
Destination=input("Enter Destination to display")
for i in Data:
if i[3]==Destination:
print(i)
File.close()

Courier_Add()
Courier_Search()
Subscribe for More
https://www.youtube.com/@TECHQueenLovejeetArora

import csv
#book_Id,B_Name,Pub
#BookId,BookName,Publisher
def Add_Book():
File=open("Data.csv","w",newline="")
ObjWrite=csv.writer(File)
ObjWrite.writerow(["BookId","BookName","Publisher"])
while True:
Book_Id=int(input("Enter Book_Id"))
B_Name=input("Enter B_Name")
Pub=input("Enter Publisher")
List=[Book_Id,B_Name,Pub]
ObjWrite.writerow(List)
Ch=input("Enter Y or y for more Data")
if Ch not in "Yy":
break
File.close()
def Search_Book():
File=open("Data.csv","r")
Data=csv.reader(File)
Publisher=input("Enter Publisher Name")
Count=0
for i in Data:
if i[2]==Publisher:
Count+=1
print(i)
print("Total Book By thi Publisher is - ",Count)
File.close()

Add_Book()
Search_Book()
Subscribe for More
https://www.youtube.com/@TECHQueenLovejeetArora

import csv
#T_id,Tname,Desig
#TeacherId,TeacherName,Designation
def Add_Teacher():

File=open("Data.csv","w",newline="")
ObjWrite=csv.writer(File)

ObjWrite.writerow(["TeacherId","TeacherName","Designation"])
while True:
T_Id=int(input("Enter Techer Id"))
Tname=input("Enter Teacher Name")
Desig=input("Enter Designation")
List=[T_Id,Tname,Desig]
ObjWrite.writerow(List)
Ch=input("Enter Y or y for more Data")
if Ch not in "Yy":
break
File.close()
def Search_Teacher():
File=open("Data.csv","r")
Data=csv.reader(File)
Count=0
for i in Data:
if i[2]=="PGT":
Count+=1
print(i)
print("All PGT's - ",Count)
File.close()

Add_Teacher()
Search_Teacher()
Subscribe for More
https://www.youtube.com/@TECHQueenLovejeetArora

import csv
def Add_Device():

File=open("Data.csv","w",newline="")
ObjWrite=csv.writer(File)
ObjWrite.writerow(["Device Id","Device Name","Price"])
while True:
P_Id=int(input("Enter Device Id"))
P_name=input("Enter Device Name")
Price=input("Enter Price")
List=[P_Id,P_name,Price]
ObjWrite.writerow(List)
Ch=input("Enter Y or y for more Data")
if Ch not in "Yy":
break
File.close()
def Count_Device():
File=open("Data.csv","r")
Data=csv.reader(File)
Count=0
next(Data)
for i in Data:
if int(i[2])<1000:
Count+=1
print(i)
print("Total Device - ",Count)
File.close()

Add_Device()
Count_Device()
Subscribe for More
https://www.youtube.com/@TECHQueenLovejeetArora

import csv
def Accept():
File=open("Data.csv","w",newline="")
ObjWrite=csv.writer(File)
ObjWrite.writerow(["Student Id","Student Name","Student
Game","Result"])
while True:
St_Id=int(input("Enter Student Id"))
St_Name=input("Enter Student Name")
Game_Name=input("Enter Game Name")
Result=input("Enter 'Won','Lost','Tie'")
List=[St_Id,St_Name,Game_Name,Result]
ObjWrite.writerow(List)
Ch=input("Enter Y or y for more Data")
if Ch not in "Yy":
break
File.close()
def WonCount():
File=open("Data.csv","r")
Data=csv.reader(File)
Count=0
for i in Data:
if i[3]=='Won':
Count+=1
print(i)
print("Total Won - ",Count)
File.close()
#Accept()
WonCount()

import csv
def ADD():
File=open("Data.csv","w",newline="")
ObjWrite=csv.writer(File)
ObjWrite.writerow(["Employee Id","Employee Name","Employee Salary"])
while True:
Empid=int(input("Enter Employee Id"))
Name=input("Enter Employee Name")
Salary=input("Enter Employee Salary")
List=[Empid,Name,Salary]
ObjWrite.writerow(List)
Ch=input("Enter Y or y for more Data")
if Ch not in "Yy":
break
File.close()
def Countr():
File=open("Data.csv","r")
Data=csv.reader(File)
next(Data)
print("Total Record - ",len(list(Data)))
File.close()
#ADD()
Countr()
Subscribe for More
https://www.youtube.com/@TECHQueenLovejeetArora

import csv
def ADD():
File=open("Data.csv","w",newline="")
ObjWrite=csv.writer(File)
ObjWrite.writerow(["Furniture Id","Furniture Name","Furniture Price"])
while True:
fid=int(input("Enter Furniture Id"))
FName=input("Enter Furniture Name")
fprice=input("Enter Furniture Price")
List=[fid,FName,fprice]
ObjWrite.writerow(List)
Ch=input("Enter Y or y for more Data")
if Ch not in "Yy":
break
File.close()
def Search():
File=open("Data.csv","r")
Data=csv.reader(File)
next(Data)
for i in Data:
if int(i[2])>10000:
print(i)

File.close()
ADD()
Search()
To watch its Solutions - https://www.youtube.com/watch?v=45QYA2zU55g

You might also like