Exercise 7.2

Exercise 7.2#

Question 1#

Calculate the following sum using a for loop:

i=0503i2+i

(The answer is 130050)

Question 2#

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

T0=0Tn=Tn1+3

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 ex, using the first N terms. Both N and x must be provided by the user. Remember:

    ex=1+x+x22!+x33!+x44!++xNN!

    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).