1. Write a Python class that extends the Progression class so that each value in
ID: 3879076 • Letter: 1
Question
1. 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.
2. Develop an inheritance hierarchy based upon a Polygon class that has abstract methods area( ) and perimeter( ). Implement classes Triangle, Quadrilateral, Pentagon, Hexagon, and Octagon that extend this base class, with the obvious meanings for the area( ) and perimeter( ) methods. Also implement classes, IsoscelesTriangle, EquilateralTriangle, Rectangle, and Square, that have the appropriate inheritance relationships. Finally, write a simple program that allows users to create polygons of the various types and input their geometric dimensions, and the program then outputs their area and perimeter.
3. Write a Python class that extends the Progression class so that each value in the progression is the absolute value of the difference between the previous two values. You should include a constructor that accepts a pair of numbers as the first two values, using 2 and 200 as the defaults.
4. Implement the mul method for the Vector class of Section 2.3.3, so that the expression u v returns a scalar that represents the dot product of the vectors, that is, d i=1 ui · vi.
5. Our Range class, from Section 2.3.5, relies on the formula max(0, (stop start + step 1) // step) to compute the number of elements in the range. It is not immediately evident why this formula provides the correct calculation, even if assuming a positive step size. Justify this formula, in your own words.
Explanation / Answer
Hope you know chegg policy of 1 question per submission
//#main.py
from progression import Progression
from math import sqrt
class SquareProgression(Progression):
def __init__(self, val=65536):
super().__init__(val)
def _advance(self):
self._current = sqrt(self._current)
if __name__ == '__main__':
x = SquareProgression()
x.print_progression(10)
============================================================================
#Progression.py
class Progression:
def __init__(self, start=0):
self._current = start
def _advance(self):
self._current += 1
def __next__(self):
if self._current is None:
raise StopIteration
else:
answer = self._current
self._advance()
return answer
def __iter__(self):
return self
def print_progression(self, n):
print(' '.join(str(next(self)) for _ in range(n)))
if __name__ == '__main__':
x = Progression()
x.print_progression(1900)
============================================================================
sample output
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.