Question

Consider the following implementation of the method magic(...)
on a dynamic array. What operation does it actually perform on a
given dynamic array? ***WRITTEN IN PYTHON 3***

**def magic(self) -> None:**

** for i in
range(self.size - 1, -1, -1):**

** self.append(self.data[i])**

** self.remove_at_index(i)**

** return**

Answer #1

magic() method is executing a loop which is running for i=size-1 to 0 and value of i is decremented by 1 in each iteration. That is

i will be size -1,...... 4,3,2,1,0

And in each iteration value from a list at index i that is
**data[i]** is appended at the end of dynamic array by
using the **self.append() .**

Value at index i is also getting removed from the dynamic array.

These two operation will be executed for each iteration that means values will be removed at each index of the dynamic array. And newer values wil be added to replace them from the data list.

Simply saying, magic() will remove all the values and replace them with the values from the data list in the dynamic array while maintaining the same indices.

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 =...

"""
'''
Write a python code to
push all zeors to the end of an array
'''
import numpy as np
def Move_a(i):
num = len(a)
for k in range (i, num-1):
a[k] = a[k+1]
a[num-1] = 0
return a
a = np.array([0,1,4,7,0,9,12,0,0,15,0,21])
#length of array (len)
num = len(a)
print (num)
for i in range(0,num):
if (a[i] == 0):
#Functioon call to Move_a()
a = Move_a(i)
print ("the array looks like")
print (a)
My...

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...

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 {...

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...

Consider the following recursive algorithm. Algorithm Test
(T[0..n − 1]) //Input: An array T[0..n − 1] of real numbers if n =
1 return T[0] else temp ← Test (T[0..n − 2]) if temp ≥ T[n − 1]
return temp else return T[n − 1] a. What does this algorithm
compute? b. Set up a recurrence relation for the algorithm’s basic
operation count and solve it.

For each of the following Python programs P and input strings I,
give the output P(I), using the formal definition of P(I) given,
and employing any reasonable reference computer C:
Definition of P(I), the output of a Python program. Let P be a
Python program with respect to a reference computer system C.
Suppose P has main function M, and let I be a string of ASCII
characters that will be used as input to P. The output of P...

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...

What output do we get? How do we get that output?
Consider the following method :
public static void processArray (int [] array) {
int x = 0;
for (int i = 0; i < array.length - 1; i++ ) {
if (array [i] < array [i+1]) {
System.out.println (i + 1) ;
}
}
}
In the left-hand column below are specific arrays of integers.
Indicate in the right- hand column what value would be printed by...

Consider the statement, "If you will give me magic beans,
then I will give you a cow." Decide whether each statement
below is the converse, the contrapositive, or neither.
1. You will give me magic beans and I will not
give you a cow.
2. If you will give me magic beans, then I will
not give you a cow.
3. If I will give you a cow, then you will not
give me magic beans.
4. If I will...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 5 minutes ago

asked 5 minutes ago

asked 9 minutes ago

asked 59 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 2 hours ago

asked 2 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago