Lab 07 Marked Assignment 3 Monday Solution

Lab 07 Marked Assignment 3 Monday Solution - # more useful...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 # William M. Farmer # 9 November 2010 # # This is a solution for Lab 07: Marked Assignment 3 on Monday. # Implements f_1 def fun1(n): return (n ** 3) - 1 # Implements f_2 def fun2(n): val = 0 for i in range(n + 1): val = val + (i * fun1(i)) return val # Implements f_3 def fun3(m,n): list = [] for i in range(m, n + 1): list = list + [fun1(i)] return list # Design Question # # Yes, this is a good approach. The function fun4 is more general and
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # more useful than fun2, but not any harder to write. And fun2 can be # immediately defined in terms of fun4: # # def fun2(n): # return fun4(0,n) # # Testing Question # # Only one test case is needed because, when n is negative, # # range(n + 1) # # is and so the body of the for loop is never executed. That is, # fun2 behaves exactly the same for all negative inputs....
View Full Document

This note was uploaded on 09/28/2011 for the course 1D04 ENG1D04 taught by Professor Smith during the Summer '10 term at McMaster University.

Ask a homework question - tutors are online