Exercises
Exercises#
After completing the tutorial attempt the following exercises.
If you are not sure how to do something, have a look at the “How To” section.
Write a function that generates \(n!\).
Write a function that generates the \(n\)th triangular numbers defined by:
\[ T_n = \frac{n(n+1)}{2} \]Verify the following that the following identify holds for positive integer values \(n\leq 500\):
\[ \sum_{i=0}^n T_i = \frac{n(n+1)(n+2)}{6} \]Consider the Monty Hall problem:
Write a function that simulates the play of the game when you ‘stick’ with the initial choice. You might find
random.shuffle
andpop
ing a list helpful.Write a function that simulates the play of the game when you ‘change’ your choice. You might find
remove
ing from a list helpful.Repeat the play of the game using both those functions and compare the probability of winning.