# hw6b - code is entered into Python(i x...

This preview shows pages 1–2. Sign up to view the full content.

Suggested Homework #6 Suggested Homework #6 (for Quiz #6 on 11/2/06) Problem 1: (a) What is the difference between assignment and mutation ? (b) What are three differences between ML's environment and Python's namespace ? (c) In each of the following pieces of Python code, indicate by circling the appropriate parts, where in the code assignment is taking place and where mutation is taking place. (i) s = range(10) for i in s: s[i] = s[i] + 1 i = i + 1 (ii) s = [[x] for x in range(10)] for [i] in s: s = s + s[i] (iii) s = [[x] for x in range(10)] for [i] in s: s[i] = s + s[i] Problem 2: (a) When are variables x1,x2,. ..,xn said to be aliases ? (b) For each of the following, which variables are aliased after the

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: code is entered into Python ? (i) x = ["a","b","c"] y = [1,2,3,4,x] z = y[4] (ii) y = ["a","b","c"] z = [1,2,3] http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw6.html (1 of 2) [2/13/2008 5:25:32 PM] Suggested Homework #6 def f(x): x = z f(y) (iii) x = [1,2,3] z = 10 def f(y): x[0] = y x[1] = x[0] f1 = f f1(z) w = x[1] Problem 3: What is the value of z at the end of the following program: x=[0] def f(y): def g(): x[0] = x[0] + 1 y[0] = y[0] + 1 return(y[0],x[0]) return g g1 = f([10]) g2 = f([100]) z = [g1(),g1(),g1(),g1(),g2(),g2(),g2(),g2()] http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw6.html (2 of 2) [2/13/2008 5:25:32 PM]...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

hw6b - code is entered into Python(i x...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online