मराठी

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: - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

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:

  1. ADD() - To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with field elements such as empid, name, and mobile to store an employee id, employee name, and employee salary respectively.
  2. COUNTR() - To count the number of records present in the CSV file named ‘record.csv’.
थोडक्यात उत्तर
Advertisements

उत्तर

Advantages of a CSV file:

  • It is human readable - can be opened in Excel and Notepad applications.
  • It is just like a text file.
Program:

import csv
def ADD():
fout=open("record.csv","a",newline="\n")
wr=csv.writer(fout)
empid=int(input("Enter Employee id :: "))
name=input("Enter name :: ")
mobile=int(input("Enter mobile number :: "))
lst=[empid,name,mobile] ---------1/2 mark
wr.writerow(lst) ---------1/2 mark
fout.close()

def COUNTR():
fin=open("record.csv","r",newline="\n")
data=csv.reader(fin)
d=list(data)
print(len(d))
fin.close()

ADD()
COUNTR()
shaalaa.com
Read and Write a CSV File Using Python
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2022-2023 (March) Sample
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×