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

  • 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'm learning how to write loops in Python 3+ but need help in solving this function...

    I'm learning how to write loops in Python 3+ but need help in solving this function with another function: def babylonian_square_root(N, estimate, precision): new_estimate = (estimate + (N / estimate)) / 2 # I need to complete this using this function close_enough(). def close_enough(x, y, maximum_allowable_difference): ''' Returns True if x and y are within maximum_allowable_difference of each other. ''' # Note: "maximum" implies that we should use <= , but for this to work mathematically we need to use...

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

  • I need a python 3 help. Please help me with this question Part 2. Linked Lists...

    I need a python 3 help. Please help me with this question Part 2. Linked Lists You start working with the class LinkNode that represents a single node of a linked list. It has two instance attributes: value and next. class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Before you start with the coding questions, answer the following questions about the constructor Valid Constructor or Not? LinkNode(1, 3) LinkNode(1, None) LinkNode(1,...

  • please help with how the flow chart will look like? thank you! Synthesis of n-Butyl Bromide...

    please help with how the flow chart will look like? thank you! Synthesis of n-Butyl Bromide Purpose of the Experiment: In this week's experiment you will be synthesizing n-butylbromide (IUPAC 1-bromobutane from 1-butanol and a concentrated acid via a nucleophilie substitution reaction. It is important to know that alcohols dehydrate to form alkenes in the presence of strong inorganic acids, so care must be taken in this experiment not to heat the reaction too vigorously else an elimination reaction may...

  • Something is preventing this python code from running properly. Can you please go through it and...

    Something is preventing this python code from running properly. Can you please go through it and improve it so it can work. The specifications are below the code. Thanks list1=[] list2=[] def add_player(): d={} name=input("Enter name of the player:") d["name"]=name position=input ("Enter a position:") if position in Pos: d["position"]=position at_bats=int(input("Enter AB:")) d["at_bats"] = at_bats hits= int(input("Enter H:")) d["hits"] = hits d["AVG"]= hits/at_bats list1.append(d) def display(): if len(list1)==0: print("{:15} {:8} {:8} {:8} {:8}".format("Player", "Pos", "AB", "H", "AVG")) print("ORIGINAL TEAM") for x...

  • E Section 3: 2 Scores/Percentiles and Hypothesis Testing Please show work. You wil need to refer ...

    e Section 3: 2 Scores/Percentiles and Hypothesis Testing Please show work. You wil need to refer to Z score tables for this rtin 6. The national (population) average for ACT scores is 208 (on a 36 point a. Suppose you score 26 on does this score fall? (Find your ACT. At approximately what percentile (round to the nearest integer between 1 and 99) your probability from the Z table, subtract that from 1, multiply by 100, and round) Answer that...

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
ADVERTISEMENT