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

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

View Full Document Right Arrow Icon
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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

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 Right Arrow Icon
Ask a homework question - tutors are online