Learn

Congratulations, we have completed the first step to our induction proof! Next comes the inductive step, which begins with our definition of the induction hypothesis. The induction hypothesis supposes that our statement is true for some integer k, with the caveat that k must exceed the number set as the base case (Mazur 95).

Recall that we supposed that for any positive integer n:

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

Using the definition of induction hypothesis as well as the fact that we defined the base case as k = 1 in the previous exercise, we can reword this conjecture to say this: For some integer k in which k > 1:

i=1k(2i1)=k2\sum^k_{i=1} (2i-1) = k^2

We will use Python to code this hypothesis through the upcoming checkpoints. For convenience, we will set the variable k equal to nine.

Instructions

1.

First, create a variable called s and set it equal to the default value of 0.

2.

Next, set s to store the sum of first i odd integers, where i is a value starting at 1 and increments each iteration until the first k odd integers have been added together. In other words, rewrite:

i=1k(2i1)\sum^k_{i=1} (2i-1)

using a Python script. Print s to ensure that the code worked properly.

3.

Finally, use the == comparison operator to write a Python script that prints whether or not s really does equal k**2.

Take this course for free

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