Beginners question



Is there anyone that can help me out here? Have run out of ideas how to solve it



Listen to our story: a boy and his father, a computer programmer, are playing with wooden blocks. They are building a pyramid. Their pyramid is a bit weird, as it is actually a pyramid-shaped wall - it’s flat. The pyramid is stacked according to one simple principle: each lower layer contains one block more than the layer above.

The figure illustrates the rule used by the builders.


Your task is to write a program which reads the number of blocks the builders have, and outputs the height of the pyramid that can be built using these blocks.

Note: the height is measured by the number of fully completed layers - if the builders don’t have a sufficient number of blocks and cannot complete the next layer, they finish their work immediately.


That text tells you what to do, it’s a simulation problem - read it carefully. It says what information is being sought, and it tells you how to produce that information


Right… I understand what to do, but I don’t know how…
this is how far I’ve com sofar

blocks = int(input(”Number of blocks: ”))

print(”Height of pyramid:”,height)


And then you’d simulate building it to see how far you get.

Note that you can also write an equation for how the height relates to the number of blocks used, which would be a one-liner answer (basically just treating python like a calculator, keying in the math) (roughly 10th grade math, quadratic equations)


Like this?

blocks = int(input(”Number of blocks: ”))
i = 1
while(blocks >= i)
blocks -= i

print(”Height of pyramid:”,height)


something like that.


Try to run but get this…

File “”, line 5
while(blocks >= i)
SyntaxError: invalid syntax

solved it…

while blocks >=i:

the I´m stuck…Hint please! =)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.