The error is caused by scope. Inside the `else`

clause you're using the variable `findmid1`

which it can't access, because you created it in the `if`

clause.

This is not the biggest error. The biggest error is your code logic. I'm not gonna tell you how to do it, because I would be giving the answer (which is no fun, right ). Instead, I'll give you a general way to go about solving these problems.

#### Write down cases

Write down all the boundary cases that you can think of and add the answer as well.

In this case, there are several boundary cases you could think of:

- len(l) is 0
- len(l) is 1
- len(l) is even
- len(l) is odd

Write down an example for each, together with the answer it should give.

### Try to solve it like your algorithm would

For each example, write down the indices below it and see if you're getting the answers you want to get. Don't forget to write down what operation you're using (for instance dividing by 2).

#### Write down the code

Try to just follow the general steps you took in solving it by hand.

#### Debug

If it still doesn't work, debug! Add as many print statements as you might need to solve the problem and to see what's wrong. Give your examples as arguments and check if it does the right thing.

Following these steps, you should be able to solve it. If you come upon something you can't solve, feel free to ask!