#CS 0008: Spring 2015 Lab 5 #YOUR NAME: #YOUR PARTNER'S NAME: # # Working with a list of lists and string indices. Look for "TODO" to see what # to do. You can enter your answers into this file. # def grade(myAns,correctAnswer): if myAns == correctAnswer: print("Correct, the answer is",myAns) else: print("My answer is",myAns,"but the correct answer is",correctAnswer) def where(s,c): '''Given string s and single-character string c, return the position of the first occurrence of c in s. If c is not in s, return -1.''' # Do not use any string methods, but you can use functions in __builtins__ # # Remember that the positions of strings and list are numbered, starting # at 0. s = 'next'; s[0] is 'n'; s[1] is 'e'; and so on. # def main(): #START HERE: #The following is a list of lists, where the inner lists consist of an ID and a grade average student_grades = [['999888777', 78.0], ['111222333', 90.0], ['444555666', 83.0]] # Here is an example of a nested loop. TODO: Run and trace this until you are sure you understand it for student in student_grades: print(student) for x in student: print(x) # Now we'll start using a list of measurements measurements = [[33, 34, 30], [29, 31, 34], [28, 27, 30]] print ("measurements is",measurements) # TODO Write code here to print the average of each inner list # For example, for 'measurements', the averages are 32.333333, 31.333333, and 28.333333 # TODO Now do the same thing, but using the builtin function "sum". # enter 'help(sum)' in the Shell to see how to use it. # TODO read the header and docstring for function 'where' (above). # Here, create a set of at least 5 test cases for 'where' and call 'grade' # as in lab5 (grade is above). Then, write function 'where' and test it. main()