Skip to content

Latest commit

 

History

History
50 lines (45 loc) · 1.8 KB

1.Describe_the_problem.md

File metadata and controls

50 lines (45 loc) · 1.8 KB

1. Describe the problem

If you don't understand what the problem is you can't fix it. BREAK IT DOWN

def my_function():
    for i in range(1,20):
        if i == 20:
            print("You got it")

Here is a small function... now what does it do? we go from the top.

  • Function declaration

        def my_function():
  • For loop execution

    for i in range(1,20):

    now what is it and what does it do? it is a for loop that runs from range(1,20)

  • If statement

        if i == 20:
            print("you got it")

    This if statement is setup to print "you got it" when i is equal to 20.right?

Try to run this code and see what happens. You get nothing right? why would that be? the code gives no errors and runs but you get no input.

this is a BUG and now we SQUISH IT

for us to squish the bug we have to understand how our progam works.

  1. Now the print statement isn't getting executed.
  2. Which would mean that the if statement requirements aren't being met
  3. With this information we can assume that there must be a problem with the for loop
  4. What could be wrong with the for loop? the syntax is fine as there was no error. there must be something wrong with the range
  5. Now if we look at the range, that is from 1 to 20, we find out that the loop never goes to 20 but stops at 19 because that is how range funciton works
  6. Which tells us that if we increment the 20 to 21 we will be able to solve our problem
def my_function():
    for i in range(1,21):
        if i == 20:
            print("You got it")

Now try to run it again. your print statement will work flawlessly. We looked at the code broke it down into pieces looked at each piece and found the bug and squished it