Stirling's Approximation

Question

Stirling's Approximation for $\ln n!$ is:

$$\ln n! \approx n \ln n - n.$$

Write a program to output $\ln n!$, its Stirling's approximation and the relative error in the approximation, (exact-approx)/exact, for $n < 100$. Then modify the program to output only the first value of $n$ for which the relative error is less than 1%. Hint: the math module provides ("exposes") a factorial() method.

Solution

To access solutions, please obtain an access code from Cambridge University Press at the Lecturer Resources page for my book (registration required) and then sign up to scipython.com providing this code.