# adopted from
# https://www.geeksforgeeks.org/working-csv-files-python/

import csv

# field names,  CGPA means Cumulative Grade Point Average.
fields = ['Name', 'Branch', 'Year', 'CGPA']

# data rows of csv file
rows = [['Nikhil', 'COE', '2', '9.0'],
        ['Sanchit', 'COE', '2', '9.1'],
        ['Aditya', 'IT', '2', '9.3'],
        ['Sagar', 'SE', '1', '9.5'],
        ['Prateek', 'MCE', '3', '7.8'],
        ['Sahil', 'EP', '2', '9.1']]

# name of csv file
filename = "university_records.csv"

# writing to csv file
# note: newline=''
# may be used to suppress empty lines in the output file

with open(filename, 'w', newline='' ) as csvfile:
  # creating a csv writer object
  csvwriter = csv.writer(csvfile)

  # writing the fields
  csvwriter.writerow(fields)

  # writing the data rows
  csvwriter.writerows(rows)

