Added cells for notebook exercise

parent 8bfadd23
{
"cells": [],
"cells": ["cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# À propos de pi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Some mathematical formulas:\n",
"$\\pi = \\frac{C}{D}$\n",
"$$ \\pi \\approx 3.14 $$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"print(math.pi)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Learn more here: [Aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"import math\n\n",
"def buffon_needle(n):\n",
" count = 0\n",
" for _ in range(n):\n",
" x = random.uniform(0, 1)\n",
" theta = random.uniform(0, math.pi / 2)\n",
" if x <= math.sin(theta):\n",
" count += 1\n",
" return (2 * n) / count\n\n",
"print(buffon_needle(100000))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n\n",
"x = np.linspace(0, 2 * np.pi, 100)\n",
"y = np.sin(x)\n\n",
"plt.plot(x, y)\n",
"plt.title(\"Sine Wave\")\n",
"plt.xlabel(\"x\")\n",
"plt.ylabel(\"sin(x)\")\n",
"plt.grid(True)\n",
"plt.show()"
]
}
]
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment