Objectives (help all)

Familiarize the student with:
using the while loop;
finding the proper implementation of verbally defined rules;
reflecting real-life situations in computer code.
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

1 Like

blocks = int(input("Enter the blocks : "))

i=1
layer=1
height=0

while i<blocks+1:
height+=layer
if height>blocks:
print(layer-1)
break
i+=1
layer+=1