Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me make add a menu to this program, as well as the correspondin

ID: 3847785 • Letter: C

Question

Can someone help me make add a menu to this program, as well as the corresponding functions that will allow users to print the data, delete a row or column, insert a row or column, change a value in a cell and output the data in CSV format?


_______MAIN.PY_________
#Import libraries
import csv
#Define a method
def csv_reader(fobj):
   #Define reader
   reader = csv.DictReader(fobj, delimiter=',')
  
   #Loop until length
   for line in reader:
       #Display
       print(line["surname"], line["last name"])
#If main
if __name__=="__main__":
   #Open file
   with open("data.csv") as fobj:
       #Call method
       csv_reader(fobj)
#Define a method
def csv_writer(data, path):
   #Open file
   with open(path, "wb") as csv_file:
       #Call method
       writer = csv.writer(csv_file, delimiter=",")
       #Loop until length
       for line in data:
           #Call method
           writer.writerow(line)
#If main
if __name__=="__main__":
   #Define data
   data = ["StreetNumber, surname, lastname, Landmark ,city".split(",") ,"1 ,Fred, Flintstone,301 Cobblestone way, Bedrock".split(',')]
   #Define path
   path = "output.csv"
   #Call method
   csv_writer(data, path)
   #Declare list
   my_list = []
   #Set name
   fieldnames = data[0]
  
   #Loop until length
   for values in data[1:]:
       #Call method
       inner_dict = dict(zip(fieldnames, values))
       #Append
       my_list.append(inner_dict)
  
   #Define path
   path = "dict_output.csv"
   #Call method
   csv_writer(fieldnames,path)

__________DATA.CSV___________
1,Fred Flintstone,301 Cobblestone Way, Bedrock
2,Wilbur Robinson,245 Redding Drive,San Diego

Explanation / Answer

#Import libraries
import csv
#Define a method
def csv_reader(fobj):
   #Define reader
   reader = csv.DictReader(fobj, delimiter=',')
  
   #Loop until length
   for line in reader:
       #Display
       print(line["surname"], line["last name"])
#If main
if __name__=="__main__":
   #Open file
   with open("data.csv") as fobj:
       #Call method
       csv_reader(fobj)
#Define a method
def csv_writer(data, path):
   #Open file
   with open(path, "wb") as csv_file:
       #Call method
       writer = csv.writer(csv_file, delimiter=",")
       #Loop until length
       for line in data:
           #Call method
           writer.writerow(line)
#If main
if __name__=="__main__":
   #Define data
   data = ["StreetNumber, surname, lastname, Landmark ,city".split(",") ,"1 ,Fred, Flintstone,301 Cobblestone way, Bedrock".split(',')]
   #Define path
   path = "output.csv"
   #Call method
   csv_writer(data, path)
   #Declare list
   my_list = []
   #Set name
   fieldnames = data[0]
  
   #Loop until length
   for values in data[1:]:
       #Call method
       inner_dict = dict(zip(fieldnames, values))
       #Append
       my_list.append(inner_dict)
  
   #Define path
   path = "dict_output.csv"
   #Call method
   csv_writer(fieldnames,path)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote