{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Module 2" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from random import random \n", "N=10000\n", "val=sum(\n", "1 for _ in range(N)\n", " if random()**2 + random()**2 <= 1\n", ")\n", "\n", "pi_estimate = 4 * val / N" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.1672" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pi_estimate" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a x b = 196\n" ] } ], "source": [ "a=14\n", "b=14\n", "prod=a*b\n", "print(\"a x b =\", prod)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import matplotlib.pyplot as plt\n", "\n", "x = [1,2, 3, 4]\n", "y = [4, 8, 12, 16]\n", "\n", "plt.plot(x, y)\n", "plt.title( \"Plot\")\n", "plt.xlabel(\"x\")\n", "plt.ylabel(\"y = 4x \")\n", "plt.show()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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 }