@extends('template')
@section('title')
Lab 12: Fruitful recursion
@stop
@section('content')
# Lab 12, Part 1: Simple fruitful recursion
__Create a new file in your `lab12` folder called `fruitful.py`__ and
complete the following tasks. You can use the provided `test_fruitful.py`
file to test each task as you complete it.
Remember to use [the case-by-case recursive problem solving
method](case-by-case) to help you see the recursive patterns.
## Task 1. `sumUpTo`
Partner A
Write a **fruitful recursive** function called `sumUpTo` that will take an integer and return the sum of all numbers up to and including that integer.
(You saw this function in lecture, but attempt it without refering to your notes.)
[Click here for a sketch of the function call diagrams](/content/labs/lab12/images/sumUpToHint.png)
For example:
```py
sumUpTo(0) # returns 0
sumUpTo(3) # returns 6 (because 3 + 2 + 1 = 6)
sumUpTo(10) # returns 55
sumUpTo(88) # returns 3916
sumUpTo(500) # returns 125250
sumUpTo(1000) # --> ERROR maximum recursion depth exceeded
```
Make sure that your function actually **returns** a value (as opposed to merely printing it).
Here's a way to test it — add the following line to your file and run it...
```py
print(sumUpTo(10))
```
...it should produce the number `55`. If it produces `None`, then your function _prints_ rather than _returns_ the value and it needs to be fixed.
## Task 2. `addToEach`
Partner B
Write a **fruitful recursive** function called `addToEach` that will take a list of numbers and a number to add, and which returns a list where the number to add has been added to each of the numbers in the original list. For example:
```py
addToEach([1, 2, 3], 3) # returns [4, 5, 6]
addToEach([], 5) # returns []
addToEach([1, 1], 1) # returns [2, 2]
```
## Task 3. `countLs`
Partner A
Write a **fruitful recursive** function called `countLs` that takes a
string and returns the number of times the letter 'L' appears in the
string (either upper- or lower-case).
```py
countLs("") # returns 0
countLs("apple") # returns 1
countLs("Lollipop") # returns 3
countLs("win") # returns 0
```
@include('/labs/lab12/_toc')
@stop