def f( x, y ) : ''' Solves the eval.f() homework 24 problem description ''' # The + way # The + operator can combine two lists (elements of lists into one list) # [1,2,3] + [4,5,6] -> [1,2,3,4,5,6] # answer = x + y # return answer # The loop way answer = [] # Build up a list and add elements to them one at a time # Add everything in x for element in x: # Go through each element in x answer.append( element ) # Add each element in x into our answer # Add everything in y for element in y: # Go through each element in y answer.append( element ) # Add each element in y into our answer return answer # General Accumulation Function For a List # accumulator = [] # for ... # accumulator.append( ... ) # return accumulator ''' DO NOT MODIFY THE BELOW CODE '''' if ( __name__ == '__main__' ) : import eval x1 = [ ]; y1 = [ ] x2 = [ 3, 1, 4 ]; y2 = [ ] x3 = [ ]; y3 = [ 2, 7, 8 ] x4 = [ 3, 1, 4 ]; y4 = [ 1, 5, 1, 9 ] z1 = eval.f( x1, y1 ); print( 'f( x1, y1 ) =', z1 ) z2 = eval.f( x2, y2 ); print( 'f( x2, y2 ) =', z2 ) z3 = eval.f( x3, y3 ); print( 'f( x3, y3 ) =', z3 ) z4 = eval.f( x4, y4 ); print( 'f( x4, y4 ) =', z4 )