मराठी

Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has created a csv file named Result.csv, to store the results of students in different sports events. - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has created a csv file named Result.csv, to store the results of students in different sports events. The structure of

Result.csv is:

[St_Id, St_Name, Game_Name, Result]

Where

St_Id is Student ID (integer)

ST_name is Student Name (string)

Game_Name is name of game in which student is participating(string). Result is result of the game whose value can be either 'Won', 'Lost' or 'Tie'.

For efficiently maintaining data of the event, Vedansh wants to write the following user defined functions:

Accept() - to accept a record from the user and add it to the file

Result.csv. The column headings should also be added on top of the csv file.

wonCount() - to count the number of students who have won any event.

As a Python expert, help him complete the task.

थोडक्यात उत्तर
Advertisements

उत्तर

def Accept ():
     sid=int (input ("Enter Student ID "))
     sname=input ("Enter Student Name ")
     game= input ("Enter name of game ")
     res=input ("Enter Result")
     headings=["Student ID","Student Name"," Game Name", "Result"]
     data=[sid, sname, game, res]
     f=open('Result.csv','a',newline='')
     csvwriter=csv.writer (f)
     csvwriter.writerow (headings)
      csvwriter.writerow (data)
      f.close()
def wonCount ():
      f=open('Result.csv','r')
      csvreader=csv.reader(f, delimiter=',')
      head=list (csvreader)
      print (head[0])
      for x in head:
              if x[3]=="WON":
                     print (x)
       f.close()
shaalaa.com
Read and Write a CSV File Using Python
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2023-2024 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×