When using the ArithmeticProgression class of Section 2.4.2 with an increment of
ID: 3879278 • Letter: W
Question
When using the ArithmeticProgression class of Section 2.4.2 with an increment of 128 and a start of 0, how many calls to next can we make before we reach an integer of 263 or larger
this is code of section 2.4.2
class ArithmeticProgression(Progression): # inherit from Progression
2 ”””Iterator producing an arithmetic progression.”””
3
4 def init (self, increment=1, start=0):
5 ”””Create a new arithmetic progression.
6
7 increment the fixed constant to add to each term (default 1)
8 start the first term of the progression (default 0)
9 ”””
10 super( ). init (start) # initialize base class
11 self. increment = increment
12
13 def advance(self): # override inherited version
14 ”””Update current value by adding the fixed increment.”””
15 self. current += self. increment
Explanation / Answer
Answer is 2.
Explanation:
Hence, we can make 2 calls to next before we reach an integer of 263 or larger
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.