Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python class that extends the Progression class so that each value in the progression is the square root of the previous value. (Note

Write a Python class that extends the Progression class so that each value in the progression is the square root of the previous value. (Note that you can no longer represent each value with an integer.) Your constructor should accept an optional parameter specifying the start value, using 65,536 as a default

class Progression:

2 Iterator producing a generic progression.

3

4 Default iterator produces the whole numbers 0, 1, 2, ...

5

6

7 def init (self, start=0):

8 Initialize current to the first value of the progression.

9 self. current = start

10

11 def advance(self):

12 Update self. current to a new value.

13

14 This should be overridden by a subclass to customize progression.

15

16 By convention, if current is set to None, this designates the

17 end of a finite progression.

18

19 self. current += 1

20

21 def next (self):

22 Return the next element, or else raise StopIteration error.

23 if self. current is None: # our convention to end a progression

24 raise StopIteration( )

25 else:

26 answer = self. current # record current value to return

27 self. advance( ) # advance to prepare for next time

28 return answer # return the answer

29

30 def iter (self):

31 By convention, an iterator must return itself as an iterator.

32 return self

33

34 def print progression(self, n):

35 Print next n values of the progression.

36 print( .join(str(next(self)) for j in range(n)))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

5. Why does proof of transfer evidence matter?

Answered: 1 week ago