# shw7 - Suggested Homework #7 (for Quiz #7 on 12/6/07)...

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

Suggested Homework #7 (for Quiz #7 on 12/6/07) Consider the Python code below: class Count: ctr = 0 def __init__(self,init,fnext): self.ctr = init self.n = fnext def nextValue(self): return self.n(self.ctr) def next(self): self.ctr = self.nextValue() return self.ctr class DCount(Count): def nextValue(self): return self.n(self.n(self.ctr)) c = Count(1,lambda x: x + 1) d = DCount(1,lambda x: 2*x) c.next() d.next() f = d.next r1 = DCount.ctr r2 = c.ctr r3 = d.ctr r4 = f() r5 = Count.next(d) def accelerate(C,n): class aC(C): def next(self): for i in range(n): C.next(self) return self.ctr return aC E = accelerate(Count,5) e = E(0,lambda x: x + 1) r6 = e.nextValue() r7 = e.next() (a) What are the attributes of the namespace Count ? (b) What are the attributes of the namespace DCount ? (c) Which class is the super class, which class is the subclass ? (d) Which methods does the subclass inherit from the superclass ? (e)

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.

## shw7 - Suggested Homework #7 (for Quiz #7 on 12/6/07)...

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

View Full Document
Ask a homework question - tutors are online