Question: Question 1. Complete the ArithmeticSequence class so it is iterable, and outputs the consecutive numbers from low to high, using a step-size of step. For

 Question 1. Complete the ArithmeticSequence class so it is iterable, and

outputs the consecutive numbers from low to high, using a step-size of

Question 1. Complete the ArithmeticSequence class so it is iterable, and outputs the consecutive numbers from low to high, using a step-size of step. For example, the positive odd numbers less than 10 are generated from ArithmeticSequence(1, 10, 2) > 1, 3, 5, 7, 9. import collections class ArithmeticSequence(object): # 1. Complete this header, so the last argument step has a default value of 1. ! def init__(self, low, high, self.current - low # the starting number self.high-high # do not exceed this number self. step-step # the step-size # 2-3. Write the header and body for the dunder method iter . # so it simply returns itself l def f def next (self): # 4-5. If the current number is too high, raise a StopIteration exception. if self.current self.step return self.current self.step if name"main": # 6. Construct a sequence that runs from 1 up to 10: # Do not specify the step-size, which by default is 1. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 seql- # 7. Check if seal has the iter . attribute (i.e. method) print "Does seql have the iter_'attribute?", print # 8" write a simple for-loop (use n for variable) to print all the numbers in the iterator. # Use a single line, which is OK if the body has a single statement # 9" Construct an iterable for the sequence of numbers 1, 4, 7, 10, 13. Use all 3 arguments seq2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!