Module 6

Debugging functions

Finding and fixing errors in functions.

When functions do not work

Functions can have errors just like any other code. Common problems include: forgetting to return a value, wrong indentation, or misspelling the function name.

Python
# Common mistake: forgetting return
def broken_gc(seq):
    (seq.count("G") + seq.count("C")) / len(seq) * 100

result = broken_gc("ATGC")
print(result)
None

The function computes the value but does not return it. The result is None. Always use return when you want to get a value back.

What happens if a function does not use return?