Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Step 1: Guess

00:00 In the previous lesson, you wrote out the buggy program and you took a look at what you expect the output to be and what the output really is. You also got to know that the debugging steps that you will follow for the rest of this course. In this lesson, you will get started with step number one, where you will guess which section may contain the bug.

00:20 Guessing might sound a bit random, but you can actually make an educated guess of where the code might be, and in this lesson, you’ll see how you can do that.

00:31 The first step is to identify the section of code that likely contains the bug. You may not be able to identify exactly where the bug is at first, but you can usually make a reasonable guess about which section of your code has an error. So let’s try this here.

00:46 Notice that the program is split into two distinct sections. You have a function definition at the top. This is where add_underscores() is defined.

00:55 And you have a main code block that is at the bottom of your script, where you define the phrase "hello" and then also call the print() function and the add_underscores() function, passing in the phrase.

01:10 Now let’s start by looking at the main section. It says, phrase = "hello", and then calls print(), which calls add_underscores() and takes the phrase as an argument.

01:22 Do you think the problem could be here? It doesn’t look like it, right? Everything about those two lines of code looks good. So the problem is somewhere in the function definition.

01:34 Let’s take this one apart a little more. The first line in the function definition seems all right. You’re defining a new variable called new_word and assigning it to an underscore as a string. You’re all good there.

01:49 So you can conclude that the problem is somewhere in the body of the for loop. In the next lesson, you will set a breakpoint here and then start stepping through your code to see what’s going on in line 4 of your script.

Become a Member to join the conversation.