Computer Science, asked by Anonymous, 5 months ago

Anis of class 12 is writing a program to create a CSV file “mydata.csv” which will contain user name and password for some entries. He has written the following code. As a programmer, help him to successfully execute the given task.

import _____________ # Line 1
def addCsvFile(UserName,PassWord): # to write / add data into the CSV file
f=open(' mydata.csv','________') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,PassWord])
f.close() #csv file reading code
def readCsvFile(): # to read data from CSV file
with open('mydata.csv','r') as newFile:
newFileReader = csv._________(newFile) # Line 3
for row in newFileReader:
print (row[0],row[1])
newFile.______________ # Line 4
addCsvFile(“Aman”,”123@456”)
addCsvFile(“Anis”,”aru@nima”)
addCsvFile(“Raju”,”myname@FRD”)
readCsvFile() #Line 5
(a) Give Name of the module he should import in Line 1.
(b) In which mode, Aman should open the file to add data into the file
(c) Fill in the blank in Line 3 to read the data from a csv file.
(d) Fill in the blank in Line 4 to close the file.
(e) Write the output he will obtain while executing Line 5.

Answers

Answered by adwaitrane26
10

Answer:

1)import CSV

2)f=open(' mydata.csv','a')

3)newFileReader = csv.reader(newFile)

4)newFile.close()

Aman 123@456

Anis aru@nima

Rajumyname@FRD

Answered by vishakasaxenasl
2

Answer:

a)  import csv

b) f=open(' mydata.csv','a')

c) newFileReader = csv.reader(newFile)

d) newFile.close()

d) print(readCscFile())

Explanation:

  1. In the line 1, he should import the csv module in order to work with the csv files.
  2. Since he want to write the data to csv file, he should open the file in a ie append mode.
  3. For reading the data from the csv file, he can use the reader function of the csv module.
  4. A file can be closed by using the close function.
  5. Lastly, print function is used to print the output.

#SPJ3

Similar questions