<jupyter_start><jupyter_text>Debugging strategiesIn this notebook, we'll talk about what happens when you get an error message (it will happen often!) and some steps you can take to resolve them.Run the code in the next cell.<jupyter_code>x = 10

if x > 20
    print(f'{x} is greater than 20!')<jupyter_output><empty_output><jupyter_text>The "traceback" message shows you a couple of useful things:- What line the error is on: `line 3`- The class of error: `SyntaxError` (v common)- Exactly _where_ the error occured -- see where the `^` symbol is pointing?What's the problem? GooglingIf it's not immediately clear what's wrong -- if you're not even sure what a `SyntaxError` even is -- I might start by Googling the error messsage, the word "python" and maybe some keywords for what I was trying to do when I got the error. Something like [`"SyntaxError: invalid syntax" python if statement`](https://www.google.com/search?q=%22SyntaxError%3A+invalid+syntax%22+python+if+statement)Click through the first couple of links -- you'll become _very_ familiar with StackOverflow -- and see if you spot the problem.If you're still stuck, maybe it's time to ... Read the docsMy next stop would be the Python documentation to find some examples of the thing I'm trying to do. [Here's the page outlining how to write an `if` statement in Python](https://docs.python.org/3/tutorial/controlflow.html). From there, I would copy the example code, run it, compare it line by line with my code and see what's different.If I'm _still_ stuck, I might see if there are other keywords to search on and take another run at Google. Use `print()` liberallyThe `print()` function can be a lifesaver -- it can show you _what_ a value is before you try to do something to it, and whether it matches up with your expectations of what that value should be, and thereby give you a clue about why your script is failing. An example can help clarify this idea.**Scenario:** Your newsroom is handing out longevity bonuses. (Congratulations!) Each employee's bonus will be the number of years they've been with the company, times 50.So we're going to loop over our staff data, held in a list of dictionaries, and calculate each person's bonus.<jupyter_code>staff = [
    {'name': 'Fran', 'years_of_service': 2, 'job': 'Reporter'},
    {'name': 'Graham', 'years_of_service': 7, 'job': 'Reporter'},
    {'name': 'Pat', 'years_of_service': 4, 'job': 'Web Producer'},
    {'name': 'John', 'years_of_service': '26', 'job': 'Managing Editor'},
    {'name': 'Sue', 'years_of_service': 33, 'job': 'Executive Editor'}
]

for person in staff:
    name = person['name']
    bonus = person['years_of_service'] * 50
    print(f'{name} is getting a bonus of {bonus}')<jupyter_output><empty_output><jupyter_text>We didn't get an exception, but something is _clearly_ wrong with John's bonus. What's going on?Maybe you spot the error already. If not, we might Google something like ["python multiply numbers repeating"](https://www.google.com/search?q=python+multiply+numbers+repeating) -- which leads us to [this StackOverflow answer](https://stackoverflow.com/questions/20401871/want-to-multiply-not-repeat-variable). Is that what's going on here? Let's add a `print()` statement before we do the multiplication and use the [`type()`](https://docs.python.org/3/library/functions.htmltype) function to check the value that we're pulling out of each dictionary.<jupyter_code>for person in staff:
    name = person['name']
    bonus = person['years_of_service'] * 50
    print(name, type(person['years_of_service']))
    print(f'{name} is getting a bonus of {bonus}')<jupyter_output><empty_output><jupyter_text>Aha! John's value for `years_of_service` has been stored as a string, not an integer. Let's fix that by using the [`int()`](https://docs.python.org/3/library/functions.htmlint) function to coerce the value to an integer.<jupyter_code>for person in staff:
    name = person['name']
    bonus = int(person['years_of_service']) ** 2
    print(f'{name} is getting a bonus of {bonus}')<jupyter_output><empty_output><jupyter_text>Winner winner, chicken dinner.Here are some more debugging exercises for you to work through. See if you can figure out what's wrong and fix them.<jupyter_code>print(Hello, Pittsburgh!)
desk = {
    'wood': 'fir',
    'color': 'black',
    'height_in': 36,
    'width_in': 48,
    'length_in': 68
}

print(desk['drawer_count'])
students = ['Kelly', 'Larry', 'José', 'Frank', 'Sarah', 'Sue']

for student in students:
    if student = 'Kelly':
    print('It's Kelly!')
    elif student == 'José':
        print("It's José!")
import cvs

with open('../../../data/eels.csv', 'r') as o:
    reader = csv.DictReader(o)
    for row in Reader:
        print(row)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11716621253405994, 'fraction_numerical': 0.009012785579543072, 'mean_word_length': 4.68772348033373, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '1871', 'license': 'MIT', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1398, 'n_words': 585, 'path': 'reference/Debugging strategies.ipynb', 'repo_name': 'ireapps/cfj-2018', 'size': '4771'}