Question

Please help with Python code.

def pyramid_blocks (n, m, h): A solid pyramid structure (although here in the ancient Mesoamerican than the more famous ancie

testing for:

def pyramid_blocks_generator(seed):
n = 300
ns = it.islice(scale_random(seed, 3, 10), n)
ms = it.islice(scale_random(seed + 1, 3, 10), n)
hs = it.islice(scale_random(seed + 2, 2, 15), n)
yield from zip(ns, ms, hs)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution : This is program to fine total blocks required in 3D pyramid. where

n = X (bredth)

m =Y (length)

h =Z (height)

any layer contains total of n*m blockes and next layer will contains one more element in X and Y direction so the next layer contain (n+1)*(m+1)

so we can say that let first layer be L(k1) elements

L(k1) = n*m

L(k2) = (n+1)*(m+1)

L(k3) = (n+2)*(m+2)

...

...

L(kh) = (n+h-1)*(m+h-1)

and the answer will be sum of all the blocks

i.e Total_bocks = L(k1)+L(k2)+L(k3)...+L(kn)

_________________________________________________________

MATHEMATICALLY

bym y (h-l) ter blocks = first layer & and layer pth layer +(1+1)(mt) + (0+2)(2012) ..(n+h) (mth-1) NXM + um ti (nem JH+ 10 4

___________________________________________________________

FUNCTON DEFINITION IN PYTHON

############################################################

def pyramid_fast(n,m,h):
blocks = (n*h*m +(h*(h-1)//2)*(n+m)+(2*h-1)*h*(h-1)//6)
return blocks
############################################################

def pyramid(n,m,h): blocks = 0 for i in range(h): blocks+=n*m n+=1 m+=1 return blocks #function decleration take three variab

OUT

n = RESTART: /home/deeplearningcv/Documents/number_of_pyramid_block.py n = 2,m = 3, h = 1 : 66 2,m = 3, h = 10 : 570 570 n =

Add a comment
Know the answer?
Add Answer to:
Please help with Python code. testing for: def pyramid_blocks_generator(seed): n = 300 ns = it.islice(scale_random(seed, 3,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using python Blocks in pyramid def pyramid_blocks (n, m, h) A pyramid structure (although more in...

    using python Blocks in pyramid def pyramid_blocks (n, m, h) A pyramid structure (although more in the ancient Mesoamerican than the more famous ancient Egyptian style) is built from layers, each layer consistinga rectangle of identical cubic blocks. The top layer of the pyramid consists of n rows and m columns of such blocks. The layer immediately below each layer contains one more row and one more column, all the way to the bottom layer of the pyramid. If the...

  • Help with solution using Python test using def riffle_generator(seed): random.seed(seed) for i in range(1000): n =...

    Help with solution using Python test using def riffle_generator(seed): random.seed(seed) for i in range(1000): n = random.randint(0, 100) items = [random.randint(0, 10**6) for j in range(2 * n)] yield (items, True) yield (items, False) Riffle def riffle(items, out True): Given a list of items that is guaranteed to contain an even number of elements (note that the integer zero is an even number), create and return a list produced by performing a perfect riffle to the items by interleaving the...

  • Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf(&#3...

    Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf("%i %u", &N,&seed); srand(seed);    for(i=0;i { R=(double)rand()/RAND_MAX; if (R<0.5) x=x+1; else x=x-1; } printf("Final location is "); printf("%d",x); printf("\n"); } Question: Write a code that generates N pairs of random numbers. Call the first member of each pair x and the second member y. Count how many of the N pairs obey x^2+y^2<1. Call...

  • With the code given write python code that prints the probablity of getting a straight in...

    With the code given write python code that prints the probablity of getting a straight in poker when you run 10**5 trails. HELPER CODE: # We will represent cards as a string, e.g., 'AC' will be Ace of Clubs # Denominations: 2, ..., 10, 'J' = Jack, 'Q' = Queen, 'K' = King, 'A' = Ace Denominations = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] # Suits 'S' = Spades, 'H' = Hearts, 'D' = Diamonds, 'C' = Clubs Suits = ['C', 'H', 'S', 'D'] #...

  • Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk()...

    Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk() self.main.title("mine sweeper") self.define_widgets() self.mines = random.sample( [(i,j) for i in range(25) for j in range(50) ],self.CustomizeNumberOfMines()) print(self.mines) self.main.mainloop() self.CustomizeNumberOfMines() def define_widgets(self): """ Define a canvas object, populate it with squares and possible texts """ self.canvas = tk.Canvas(self.main, width = 1002, height=502, bg="#f0f0f0") self.canvas.grid(row=0, column=0) self.boxes =...

  • I need help for the order of growth for functions in Python 3. Q1: What is...

    I need help for the order of growth for functions in Python 3. Q1: What is the order of growth for the following functions? Kinds of Growth Here are some common orders of growth, ranked from no growth to fastest growth: 1. Θ(1) — constant time takes the same amount of time regardless of input size 2. Θ(log n) — logarithmic time 3. Θ(n) — linear time 4. Θ(n log n) — linearithmic time 5. Θ(n2 ) 6. Θ(n3 ),...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • Python, given a code in class i just need help with the third bullet point ; using a and n (defin...

    Python, given a code in class i just need help with the third bullet point ; using a and n (defined in the second picture of python code) find the first digit for k! for k =1,...,n. you dont have to type in all this code just help me write the code in the first picture where it says: def benford(a): b = [0 for d in range(1,10)] #Do everthything in here return b 2.2 Generating data In this assignment...

  • Using Python... Be sure to include the first line that makes the file an executable file...

    Using Python... Be sure to include the first line that makes the file an executable file in Linux. File Name: PyramidBlocks.py Python skills needed: Simple for loop (for var in range(num1,num2): Use of the range object Use of python math Creation of a Python Function Use of the print() method. Code Assignment 1: Alex sells pyramid wall art. In the design of his pyramids have each row has one more block than the last which means row 10 has 10...

  • A system has an n-layer protocol hierarchy. Applications generate messages of length M bytes. At each...

    A system has an n-layer protocol hierarchy. Applications generate messages of length M bytes. At each of the layers, an h-byte header is added. In such scenario, the fraction of bandwidth wasted on headers is hn/(M + hn). Assume that more than one (N)-PDU is encapsulated in an (N-1)-PDU. Try a few values such as 2, 3, 6, and 10. Now consider the same problem if the (N-1)-PCI is half the size of the (N)-PCI. How does this effect the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT