Lab 07 Marked Assignment 3 Friday Solution.txt

# Lab 07 Marked Assignment 3 Friday Solution.txt - # # val =...

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

# William M. Farmer # 9 November 2010 # # This is a solution for Lab 07: Marked Assignment 3 on Friday # # Implements f_1 def fun1(n): return abs(n + 1) ** 2 # Implements f_2 def fun2(m,n): val = 1 for i in range(m, (2 * n) + 1): val = val * 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 # # The first and third lines in the body of fun2 would have to be # slightly changed to:
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # # val = 0 (val should be bound to 0 instead of 1) # # and # # val = val + fun1(i) (the operator should be + instead of *), # # respectively. # # Testing Question # # The input space of fun2 divides into two obvious regions: (1) where m # &gt; 2*n (where the loop body is not executed) and (2) where m &lt;= 2*n # (where the loop body is executed). The boundary points are thus the # points (m,n) where m + 1 = n and m = n....
View Full Document

Ask a homework question - tutors are online