{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import random\n", "import math\n", "\n", "def buffon_needle(n_drops=100000):\n", " hits = 0\n", " for _ in range(n_drops):\n", " y = random.random()\n", " theta = random.uniform(0, math.pi / 2)\n", " if y <= (math.sin(theta) / 2):\n", " hits += 1\n", " return (2 * n_drops) / hits\n", "\n", "pi_est = buffon_needle()\n", "print(f\"Estimation de π par la méthode de Buffon : {pi_est}\")\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }