Beginners question


#1

Hello

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

Regards

Peter

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

image

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.


#2

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


#3

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)


#4

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)


#5

Like this?

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

print(”Height of pyramid:”,height)


#6

something like that.


#7

Try to run but get this…

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

solved it…

while blocks >=i:

the I´m stuck…Hint please! =)


#8

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