Question

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*i^{2}+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:

- You must adhere to the same rules when using the built-in Python list as you did in the ArrayList lab.
- You may not use any other data structures (this includes the built-in Python list).

class ArrayList:

def __init__(self):

self.data = []

def poly_iter(self, a, b, c):

# YOUR CODE HERE

Answer #1

**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)

Python
Mutable Sequences
Implement a function reverse that takes a list as an argument
and reverses the list. You should mutate the original list, without
creating any new lists. Do NOT return anything. Do not use
any built-in list functions such as reverse().
def reverse(lst):
"""Reverses lst in place (i.e. doesn't
create new lists).
>>> L = [1, 2, 3,
4]
>>>
reverse(L)
>>> L
[4, 3, 2, 1]
"""

Please answer the following as soon as possible. Thank you.
Add the top method in class Stack to the following python code
which returns the top item of the stack. Test it.
Design top() method using a single queue as an instance
variable, and only constant additional local memory within the
method bodies.
python code:
class Stack:
def __init__(self):
self.q = Queue()
def is_empty(self):
return self.q.is_empty()
def push(self, data):
self.q.enqueue(data)
def pop(self):
for _ in range(self.q.get_size() - 1):
dequeued =...

Python
-------------------------
### Description
In this exercise, you will add to your `Battery` class
a method to drain the battery.
### Class Name
`Battery`
### Method
`drain()`
### Parameters
* `self` : the `Battery` object to use
* `milliamps` : a number, the amount of charge to remove from the
battery.
### Action
Removes `milliamps` from the charge of the object. If the
new charge is less than 0, then set the charge to 0.
Only do this action of...

Python
Problem 1
Create a function, biggest_ip_sum, outside of the ServerClass
class, that:
1. Takes two ServerClass objects
2. Sums the octets of the IP together (example 127.0.0.1 =
127+0+0+1 = 128)
3. Returns the larger number
Example:
server_one = ServerClass("127.0.0.1")
server_two = ServerClass("192.168.0.1")
result = biggest_ip_sum(server_one, server_two)
print(result)
In the example above, result will be 361.
_________________________________
Problem 1 Here is the code to start with
class ServerClass:
""" Server class for representing and manipulating servers. """
def __init__(self,...

Python Blackjack Game
Here are some special cases to consider. If the Dealer
goes over 21, all players who are still standing win. But the
players that are not standing have already lost. If the Dealer does
not go over 21 but stands on say 19 points then all players having
points greater than 19 win. All players having points less than 19
lose. All players having points equal to 19 tie. The program should
stop asking to hit if...

[Java] I'm not sure how to implement the code. Please check my
code at the bottom.
In this problem you will write several static methods to work
with arrays and ArrayLists. Remember that a static method does not
work on the instance variables of the class. All the data needed is
provided in the parameters. Call the class Util. Notice how the
methods are invoked in UtilTester.
public static int min(int[] array) gets the minimum value in the
array
public...

Create an add method for the BST (Binary Search Tree) class.
add(self, new_value: object) -> None:
"""This method adds new value to the tree, maintaining BST
property. Duplicates must be allowed and placed in the right
subtree."""
Example #1: tree = BST()
print(tree) tree.add(10)
tree.add(15)
tree.add(5)
print(tree)
tree.add(15)
tree.add(15)
print(tree)
tree.add(5)
print(tree)
Output:
TREE in order { }
TREE in order { 5, 10, 15 }
TREE in order { 5, 10, 15, 15, 15 }
TREE in order {...

(For Python)
Evaluating Postfix Arithmetic Expressions. In this project you
are to implement a Postfix Expression Evaluator as described in
section 7-3b of the book. The program should ask the user for a
string that contains a Postfix Expression. It should then use the
string's split function to create a list with each token in the
expression stored as items in the list. Now, using either the stack
classes from 7.2 or using the simulated stack functionality
available in a...

Program will allow anywhere between 1 and 6 players (inclusive).
Here is what your output will look like:
Enter number of players: 2
Player 1: 7S 5D - 12 points
Player 2: 4H JC - 14 points
Dealer: 10D
Player 1, do you want to hit? [y / n]: y
Player 1: 7S 5D 8H - 20 points
Player 1, do you want to hit? [y / n]: n
Player 2, do you want to hit? [y / n]: y...

Problem 2: Python 3
Implement a function called gee_whiz that does the following:
given argument n, a positive integer, it returns a list of n tuples
corresponding to the numbers 1 through n (both inclusive): the
tuple for the number k consists of k as the first component, and
exactly one of the following strings as the second:
• the string 'two!' if k is divisible by 2
• the string 'three!' if k is divisible by 3
• the...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 17 minutes ago

asked 30 minutes ago

asked 30 minutes ago

asked 46 minutes ago

asked 57 minutes ago

asked 57 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago