python 3
For this exercise you are to implement the function poly_iter in the array-backed list class, which, when called with positive integer parameters a, b, c, returns an iterator over the values in the underlying list at indexes a*i2+b*i+c, for i=0, 1, 2, ...
E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98, 99], the following code:
for x in lst.poly_iter(2, 3, 4): print(x)
will produce the output:
4 9 18 31 48 69 94
Programming rules:
class ArrayList:
def __init__(self):
self.data = []
def poly_iter(self, a, b, c):
# YOUR CODE HERE
Program Code Screenshot:
Sample Output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program code to copy:
class ArrayList:
def __init__(self):
self.data=[]
def poly_iter(self,a,b,c):
l=[]
for i in range(100):#l has [0,1,2,3....99]
l.append(i)
res=0
i=0
while True:
res=(a*i*i)+(b*i)+c#compute res
if res<l[-1]:
self.data.append(res)#append to data list
else:
break
i+=1
return iter(self.data)#return itertor
lst=ArrayList()
for x in lst.poly_iter(2,3,4):
print(x)
Get Answers For Free
Most questions answered within 1 hours.