Skip to content

Commit e88db65

Browse files
authored
Create pyramid_first_last.py
1 parent 71f5b39 commit e88db65

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Week03/pyramid_first_last.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def calculate_pyramid_height(number_of_blocks):
2+
"""
3+
This function calculates the height of a pyramid
4+
given the number of blocks available.
5+
6+
A pyramid has 1 block at top, 2 blocks in second row,
7+
3 blocks in third row, etc.
8+
9+
Returns the maximum height that can be built.
10+
"""
11+
height = 0
12+
total_blocks_used = 0
13+
14+
while total_blocks_used + (height + 1) <= number_of_blocks:
15+
height += 1
16+
total_blocks_used += height
17+
18+
return height

0 commit comments

Comments
 (0)