Homework is due on Monday, 22/05/2017, 2pm
$\pi$ can be approximated with the infinite product $$\pi = 2\prod_{i=1}^{\infty}\frac{4i^2}{4i^2-1}$$ Write a Python program which approximates $\pi$ by the finite products $$\pi_{\rm approx} = 2\prod_{i=1}^{n}\frac{4i^2}{4i^2-1}$$ with $n\in \{50, 100, 1000, 10000, 20000\}$ and compare the results with the value $\pi\approx 3.1415926$ by reporting absolute $\epsilon_{\rm abs} = |\pi - \pi_{\rm approx}|$ and relative $\epsilon_{\rm rel} = \frac{|\pi - \pi_{\rm approx}|}{\pi}$ errors of the approximations.
If you hand in a script for this task, please name it wallis.py
In [ ]:
# Your solution here
In [ ]:
# your solution here
Mc Donalds sells its Chicken McNuggets in packages of 6, 9 and 20 pieces. In this exercise we want to investigate, which number of nuggets can be bought with an arbitrary combination of these package sizes.
Write a python-function can_buy which takes two arguments:
verbose whose default is set to True. See below for an explanation of the purpose of this argument.The function should return True if $N$ nuggets can be bought in package combinations of 6, 9 and 20 and False otherwise.
If the verbose-argument is set to True, the function should either print:
If the verbose-argument is set to False, the function should not print anything,
(Hint: A computer is ideal to determine a solution to a problem by trying out and testing all possibilities. You can solve this problem with this strategy and three nested while-loops)
If you hand in a script for this exercise, please name it nuggets.py. You can put code and comments for the following parts of this exercise into this script.
In [ ]:
# your solution here