Were you able to figure out that these sums created a pattern of 4, 9, 16, and 25, or n2? In fact, this turns out to be true for all of the positive odd integers: the sum of the first n odd integers does, in fact, equal n2.

In mathematical symbols, what we are saying is that for all positive integers n:

i=1n(2i1)=n2\sum^n_{i=1} (2i-1) = n^2

Induction has important applications in the computer science industry, specifically in quality assurance and case-testing. When working at any programming job, you will need to test your code for every case imaginable in order to minimize the number of errors that could occur when the product releases. A good way to case-test your code is to determine if any case creates some kind of error upon execution or compilation.

How does this idea relate to induction? We will see in the upcoming checkpoints that we need n to be a positive integer in order for our conjecture to work. To show this, we will define a number n to be nonnegative if n is an integer that is greater than or equal to zero and then we will suppose our conjecture is true for all nonnegative integers n. In other words, our new conjecture is this:

i=0n(2i1)=n2\sum^n_{i=0} (2i-1) = n^2



Let’s see why 0 will not work for the new conjecture. First, suppose we substitute 0 for n in the expression:

i=0n2i1\sum^n_{i=0} 2i-1

Simplify this by hand, then create a variable called a and set it equal to your result.


Now substitute 0 for n in the expression:


Then create a variable named b and set it equal to your result.


Lastly, use the == operator to write a Python script that prints whether or not a equals b.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?