Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Week03/pyramid_first_last.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def calculate_pyramid_height(number_of_blocks):
"""
This function calculates the height of a pyramid
given the number of blocks available.

A pyramid has 1 block at top, 2 blocks in second row,
3 blocks in third row, etc.

Returns the maximum height that can be built.
"""
height = 0
total_blocks_used = 0

while total_blocks_used + (height + 1) <= number_of_blocks:
height += 1
total_blocks_used += height

return height