#!/usr/local/cpython-3.6/bin/python3 # pylint: disable=superfluous-parens '''Compute the number of blocks in a staircase''' def num_blocks_in_stair_iterative(height): '''Compute the number of blocks in a staircase of height "height"''' total = 0 for i in range(1, height + 1): total += i return total def num_blocks_in_stair_recursive(height): '''Compute the number of blocks in a staircase of height "height"''' if height == 1: return 1 else: return height + num_blocks_in_stair_recursive(height - 1) def main(): '''Main function''' for height in range(1, 20): print(height, num_blocks_in_stair_iterative(height), num_blocks_in_stair_recursive(height)) main()