Practice

Reminder: For all of the practice problems below, make sure to return the answers rather than print them.

Factorial

Create a recursive method that mirrors how a factorial would work in math.

💻 Template code

✅ Solution code

Koch Curve

Credits to http://greenteapress.com/thinkpython2/html/thinkpython2006.html.

This is a fun problem that uses the turtle module. The goal of this problem is to create a Koch curve. More details can be found in the downloadable.

💻 Template code

✅ Solution code

List Sum

Create a recursive sequence that finds the sum of a list that may contain another list within it.

💻 Template code

✅ Solution code

Logarithm

Create a recursive method that mirrors how a logarithm works in math. You can have the base by default by ten. You do not have to deal with decimals, just worry about returning integers.

Note: logarithms return the power that you raise a base number to in order to get a number.

Ex: Logarithm of 9 to base 3 = 2; In this example, since 3 to the second power gives you 9, the logarithm of 9 to base 3 is equal to 2.

💻 Template code

✅ Solution code

Previous Section

18.6 Binary Search

Next Section

Ch. 18 Quiz