CMSC 201

Lab 9: Debugging

Welcome to lab!

Today we will practice debugging code! You will have to debug the three functions assigned to you for homework 5 (not the functions you wrote! We're giving almost working code to you.) The functions are provided as 3 separate files. Work on the first file, then after about 10 minutes whether you figured it out or not your TA will show you how to debug the code! This may seem easy but debugging is one of the most important skills you can learn, so pay attention!

BUT FIRST! A quick note on errors

There are two kinds of errors you will deal with in this lab:

  • Syntax errors, aka WHY WON'T MY CODE RUN!?! These happen when your code isn't formatted correctly, like missing a ")" or a ":", or your indentation is incorrect

  • Logic errors, aka WHY IS MY CODE NOT DOING THE THING?!? These happen when all the code in your program is grammatically correct, but the logic is messed up so it doesn't do what you are trying to make it do.

  • Sample Output:

    Should print: [1, 2, 3, 4, 5]
    Prints: []

    Final instructions

    Start with the letterCount function. This should have mostly syntax errors.
    Then do the sortList function. That one has two functions to debug with syntax AND logic errors so read the code carefully!
    Last, do the isPalindrome function. This has a big logic error so make sure you understand the code!

    def letterCount(letter):
        for i in myString:
            if i = letter:
    def main():
        print("Should print: 3\nPrints: ",end="")
    #Helper function for sortList
    def insertNum(number,myList,oldList):
        if len(myList)==0:
            for i in range(len(myList)):
                if myList[i]> number and (number not in myList):
                elif myList[i]< number and ( number not in myList):
    #sorts list
    def sortList(myList):
        newList = []
        for i in (myList):
            newList = insertNum(i,newList,myList)
    #test functions
    def main():
        print("Should print: [1,2,3,4,5]\nPrints: ",end="")
    #tests wheter a word is a palindrome
    def isPalindrome(myString):
        tempString = myString
        length = len(tempString)
        half = length/2
        for i in range(int(half):
            if myString[i] != myString[length-i]:
                isPalindrome = False
    def main():
        print("Should print: True\nPrints: ",end="")