HW: Recursion III

triangle.py

Assume we have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Write a function triangle which takes the number of rows as a parameter and calculates the number of blocks that make up the triangle. You should implement this function: (a) Recursively, and (b) Iteratively.

# of rows (parameter) # of Blocks
1 1
2 3
3 6
4 10
5 15

Test that both functions return the same value when called with the same parameters.

nox

Write a function nox that takes a string as a parameter and removes all ‘x’ characters:

Parameter (input) Returns (output)
“xendxstartx” “endstart”
“endx” “end”
“xstart” “start”
“xxxx” ””

You should implement this function: (a) Recursively, and (b) Iteratively. Test that both functions return the same value when called with the same parameters.

Submission

Once you’re satisfied that your programs are working correctly, take a screenshot of each program open in the editor, with its output displayed in the console, and submit to google classroom. You should submit 2 screenshots.