-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23_BirckBlocks
More file actions
32 lines (26 loc) · 1.26 KB
/
Copy path23_BirckBlocks
File metadata and controls
32 lines (26 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'''
Listen to this 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.
Test your code using the data we've provided.
Test Data
Sample input: 6
Expected output: The height of the pyramid: 3
Sample input: 20
Expected output: The height of the pyramid: 5
Sample input: 1000
Expected output: The height of the pyramid: 44
Sample input: 2
Expected output: The height of the pyramid: 1
'''
blocks = int(input("Enter the number of blocks: "))
# Write your code here.
height = 0
layer = 0
while layer < blocks:
layer += 1
blocks -= layer
height += 1
print("The height of the pyramid:", height)