Rubber Ducky Debugging#

If you are having troubles finding out where an error is in your code, you can also turn to ‘Rubber Ducky Debugging’. The idea of this is that it forces you to explain, in very simple language and step-by-step, what you want your code to do and what each line of code does. Your rubber ducky does not need to study engineering, they have a very simple life, so they need a very gentle introduction to your code. Often, you will find an error in the code logic while talking through it. This is not to say that your rubber ducky is not smart, they are simply smart in other ways.

You can read more about Rubber Ducky Debugging here: https://rubberduckdebugging.com/

duck

Task 4.1 Get a rubber duck#

You can have your choice of duck. If you are not able to obtain a duck, a goose (not angry) will also do the trick.

Task 4.2 Name your rubber duck#

We especially encourage pun names. This is important to build a rapport with your duck. Tip: calling your duck goose or your goose duck is always hilarious.

Task 4.3 Do some debugging!#

Below are some short snippets of code. See if you can find out what the bugs are, with your new friend.

You do not need to submit anything for this task

# This function should calculate the average, given a list of numbers

def average(numbers):
    total = 0
    for n in numbers:
        total = total + n
    avg = total / len(numbers) - 1
    return avg

print(average([3, 5, 7]))
4.0
# This function should find the highest value in a list of numbers

def find_max(nums):
    max_val = 0 
    for n in nums:
        if n > max_val:
            max_val = n
    return max_val

print(find_max([-3, -5, -1]))
0
# This function should sum all the even values in a list of numbers

def sum_evens(nums):
    total = 0
    for n in nums:
        if n % 2 == 0:
            total += n
        else:
            total = 0 
    return total

print(sum_evens([1, 2, 4, 5, 8]))
8