हिंदी

Give any one point of difference between a binary file and a CSV file. Write a Program in Python that defines and calls the following user-defined functions: - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Give any one point of difference between a binary file and a CSV file. 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 ‘furdata.csv’. Each record consists of a list with field elements such as fid, fname, and fprice to store furniture id, furniture name, and furniture price respectively.
  2. search() - To display the records of the furniture whose price is more than 10000.
संक्षेप में उत्तर
Advertisements

उत्तर

Difference between binary file and CSV file:

Binary file:

  • The extension is .dat.
  • Not human-readable.
  • Stores data in the form of 0s and 1s.

CSV file:

  • The extension is .csv.
  • Human readable.
  • Stores data like a text file.
Program:

import csv
def add():
     fout=open("furdata.csv","a",newline='\n')
    wr=csv.writer(fout)
    fid=int(input("Enter Furniture Id :: "))
   fname=input("Enter Furniture name :: ")
   fprice=int(input("Enter price :: "))
   FD=[fid,fname,fprice]
    wr.writerow(FD)
    fout.close()

def search():
     fin=open("furdata.csv","r",newline='\n')
     data=csv.reader(fin)
     found=False
     print("The Details are")
     for i in data:
         if int(i[2])>10000:
            found=True
            print(i[0],i[1],i[2])
 if found==False:
      print("Record not found")
  fin.close()
add()
print("Now displaying")
search()
shaalaa.com
Read and Write a CSV File Using Python
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Sample
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×