Exercise 7.2

Exercise 7.2#

Question 1#

Calculate the following sum using a for loop:

\[ \sum_{i = 0}^{50} 3i^2 + i \]

(The answer is \(130050\))

Question 2#

Find and print the first \(10\) terms of the following recursive series using a for loop:

\[\begin{align*} T_0 &= 0\\ T_n &= T_{n-1} + 3\\ \end{align*}\]

Question 3#

Write some code that takes a string as an input and prints it out with spaces inserted between each character. Make sure not to insert spaces before and after the string.

Question 4#

  1. Write some code that will calculate the Taylor series expansion of \(e^x\), using the first \(N\) terms. Both \(N\) and \(x\) must be provided by the user. Remember:

    \[ e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \dots + \frac{x^N}{N!} \]

    Hint: You could use math.factorial OR you could calculate a running factorial in the loop.

  2. Bonus: modify your code above to print out the solution in the form:
    “e^5 = 1 + 5 + 5^2 /2! + 5^3 /3! + 5^4 /4! = 65.375”
    where the user has chosen \(x = 5\) and \(N = 4\) in this example (make your code work in the general case).