The document defines functions to read and write to a student.csv file containing student data. The readcsv function opens the file and reads each row, printing it. The writecsv function opens the file in write mode, writes the provided sample row to the file, and closes it. The code then prompts the user to choose reading or writing the file, and calls the appropriate function.
The document defines functions to read and write to a student.csv file containing student data. The readcsv function opens the file and reads each row, printing it. The writecsv function opens the file in write mode, writes the provided sample row to the file, and closes it. The code then prompts the user to choose reading or writing the file, and calls the appropriate function.
The document defines functions to read and write to a student.csv file containing student data. The readcsv function opens the file and reads each row, printing it. The writecsv function opens the file in write mode, writes the provided sample row to the file, and closes it. The code then prompts the user to choose reading or writing the file, and calls the appropriate function.
Ques. Write user-defined functions to perform read and write
operations onto a ‘student.csv’ file having fields like roll number , name, stream and marks . import csv row=['2','Akshat Chauhan','Commerce','98'] def readcsv(): f=open("student.csv",'r') data =csv.reader(f) for row in data : print(row) def writecsv(): with open("student.csv",'w')as fav: csv_w=csv.writer(fav) csv_w.writerow(row) print("Press -1 to Read Data and Press-2 to Write Data :") a=int(input()) if a==1: readcsv() elif a==2: writecsv() else : print("Invalid Value") OUTPUT Press -1 to Read Data and Press-2 to Write Data : 1 ['1', 'Akash', 'Commerce', '88'] ['3', 'Ashi', 'Non-Medical', '90'] ['4', 'Jeet', 'Medical', '85']