# Write a function that reads a todo.csv file. # The todo.csv file contains date, time, and activity # formatted as, for example, # date,time,thingstodo # 31oct,8am,eat # 31oct,9am,relax # 31oct,10am,meet advisor # 31oct,11am,read # 31oct,12pm,eat # 31oct,1pm,get ready for cs1111 # 31oct,2pm,cs1111 # 31oct,3:30pm,some other class # 31oct,5pm,do homework # 31oct,6pm,eat # 31oct,7pm,practice writing program # where the first line is a header line # The function then counts the numbers of activities that will happen # in AM and PM, and return a dictionary containing the numbers of # AM activities and PM activities. # For example, {'number_AM_todo': 4, 'number_PM_todo': 7} def read_file(): # open todo.csv to read infile = open('todo.csv', 'r') # read the file's contents and split each line list_of_lines = infile.read().split('\n') # print(list_of_lines) number_AM_todo = 0 number_PM_todo = 0 todo_dict = {} for line in list_of_lines: # get each line # print('line =', line) # for each line, split it into columns columns = line.split(',') # print('columns =', columns) # check if the activity is AM or PM, # count number of AM activities and PM activities if "am" in columns[1] or "AM" in columns[1]: number_AM_todo += 1 elif "pm" in columns[1] or "PM" in columns[1]: number_PM_todo += 1 # put the number of AM activities and PM activities in the dict todo_dict['number_AM_todo'] = number_AM_todo todo_dict['number_PM_todo'] = number_PM_todo # close the file infile.close() return todo_dict print(read_file())