''' DS2000 Fall 2024 Starter code for lecture on 10/22/24 Complete the code for the functions below (function signatures are in the code below, along with name/params/return type). The last one is optional and just for funsies. We should get through the first three all together! ''' import random def print_row_first(lst): ''' Parameter: 2d list of any values Returns: nothing Does: Prints the element at position 0 within each list ''' def multiply_2d(lst, val): ''' parameters: 2d list of ints/floats, int/float to multiply by returns: 2d list does: computes and returns val * values in the original ''' def weighted_avg(lst): ''' parameters: 2d list with one row of floats/weights, one row of floats/values returns: float does: computes the weighted average of the given list, assuming weights are in the first row and values in the second ''' # This last one is a bonus, for funsies! Feel free to ignore def sum_rows(lst): ''' Parameters: 2d list of ints/floats Returns: 1d list of ints/floats Does: Sums each row of the given list, returns a list of sums ''' def main(): # Here in main, we're just calling the functions we've written to test them! # Mostly generating some random values to try out # Generate a 2d list with randomized values, and randomly-chosen number of # rows and columns. lst = [] num_rows = random.randint(1, 5) num_cols = random.randint(1, 8) for i in range(num_rows): row = [] for j in range(num_cols): row.append(random.randint(1, 200)) lst.append(row) # Here is my list for testing... print(lst) # Call our functions! First, print row[0] for every row print("Printing the first value in every row...") print_row_first(lst) # Second, double all the values in the list and print out doubled = multiply_2d(lst, 2) print("\n\nThis doubled the values in my list...") print(doubled) # Third, make up a new list to test weighted average weights =[.25, .3, .35, .1, .05] values = [89, 87, 98, 90, 81] scores = [weights, values] weighted = weighted_avg(scores) print("Weighted average is...", weighted) main()