Feat(Programmation): Fin du tp simulation en python

This commit is contained in:
Bertrand Benjamin 2019-01-07 08:57:46 +01:00
parent 6b3140bbc2
commit 9c2a314a6c
2 changed files with 160 additions and 163 deletions

View File

@ -13116,7 +13116,9 @@ div#notebook {
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell"> </div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html"> <div class="text_cell_render border-box-sizing rendered_html">
<h1 id="&#201;chauffements">&#201;chauffements<a class="anchor-link" href="#&#201;chauffements">&#182;</a></h1><p>Copier-coller ligne par ligne le programme suivant en corrigeant les éventuelles erreurs. Une fois le programme relu et corrigé, proposer puis coder une amélioration.</p> <h1 id="&#201;chauffements">&#201;chauffements<a class="anchor-link" href="#&#201;chauffements">&#182;</a></h1><ul>
<li>[ ] Copier-coller blocspar blocs le programme suivant en corrigeant les éventuelles erreurs (il y en a au moins une par bloc).</li>
</ul>
</div> </div>
</div> </div>
@ -13126,7 +13128,85 @@ div#notebook {
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span> <div class=" highlight hl-ipython3"><pre><span></span><span class="s2">&quot;Je veux calculer le périmètre et l&#39;aire de cercles&quot;</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">math</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Pour cela j&#39;ai besoin de Pi&quot;</span><span class="p">)</span>
<span class="n">pi</span> <span class="o">=</span> <span class="mf">3.14</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Je sais que pi vaut pi&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Mais Python connait une valeur approchée plus précise de pi, elle vaut&quot;</span><span class="p">,</span> <span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Je veux calculer le périmètre d&#39;un cercle&quot;</span><span class="p">)</span>
<span class="n">rayon</span> <span class="o">=</span> <span class="mi">3</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Quand le rayon vaut&quot;</span><span class="p">,</span> <span class="n">rayon</span><span class="p">,</span> <span class="s2">&quot;le périmètre vaut&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;On peut en faire une fonction&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">perimetre</span><span class="p">(</span><span class="n">rayon</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">4</span><span class="o">*</span><span class="n">math</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="n">rayon</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Le périmètre d&#39;un cercle de rayon 2 est &quot;</span><span class="p">,</span> <span class="n">perimetre</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<ul>
<li>[ ] Ecrire une fonction qui calcule l'aire d'un cercle à partir de son rayon.</li>
<li>[ ] Copier-coller, tester ce bloc puis expliquer avec # ce qu'il fait.</li>
</ul>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">rayon</span> <span class="o">=</span> <span class="mi">10</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;J&#39;ai un cercle de rayon&quot;</span><span class="p">,</span> <span class="n">rayon</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rayon</span> <span class="o">&lt;</span> <span class="mi">50</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;C&#39;est un petit cercle.&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;C&#39;est un grand cercle!&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Son périmètre vaut&quot;</span><span class="p">,</span> <span class="n">perimetre</span><span class="p">(</span><span class="n">rayon</span><span class="p">))</span>
</pre></div> </pre></div>
</div> </div>
@ -13160,7 +13240,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[20]:</div> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="k">import</span> <span class="n">random</span><span class="p">,</span> <span class="n">randint</span><span class="p">,</span> <span class="n">uniform</span><span class="p">,</span> <span class="n">choice</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">random</span> <span class="k">import</span> <span class="n">random</span><span class="p">,</span> <span class="n">randint</span><span class="p">,</span> <span class="n">uniform</span><span class="p">,</span> <span class="n">choice</span>
@ -13184,7 +13264,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[21]:</div> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">random</span><span class="p">()</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="n">random</span><span class="p">()</span>
@ -13194,26 +13274,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
</div> </div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="prompt output_prompt">Out[21]:</div>
<div class="output_text output_subarea output_execute_result">
<pre>0.5282588961960093</pre>
</div>
</div>
</div>
</div>
</div> </div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell"> </div><div class="inner_cell">
@ -13227,7 +13287,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[22]:</div> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">randint</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="n">randint</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
@ -13237,26 +13297,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
</div> </div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="prompt output_prompt">Out[22]:</div>
<div class="output_text output_subarea output_execute_result">
<pre>8</pre>
</div>
</div>
</div>
</div>
</div> </div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell"> </div><div class="inner_cell">
@ -13270,7 +13310,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[23]:</div> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">uniform</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="n">uniform</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
@ -13280,26 +13320,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
</div> </div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="prompt output_prompt">Out[23]:</div>
<div class="output_text output_subarea output_execute_result">
<pre>6.374949885924709</pre>
</div>
</div>
</div>
</div>
</div> </div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell"> </div><div class="inner_cell">
@ -13313,7 +13333,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
<div class="cell border-box-sizing code_cell rendered"> <div class="cell border-box-sizing code_cell rendered">
<div class="input"> <div class="input">
<div class="prompt input_prompt">In&nbsp;[26]:</div> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell"> <div class="inner_cell">
<div class="input_area"> <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># Pour définir une liste, on utilise des crochets []</span> <div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># Pour définir une liste, on utilise des crochets []</span>
@ -13326,26 +13346,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
</div> </div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="prompt output_prompt">Out[26]:</div>
<div class="output_text output_subarea output_execute_result">
<pre>&#39;français&#39;</pre>
</div>
</div>
</div>
</div>
</div> </div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div><div class="inner_cell"> </div><div class="inner_cell">
@ -13412,19 +13412,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
</div> </div>
</div> </div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span>
</pre></div>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -6,7 +6,7 @@
"source": [ "source": [
"# Échauffements\n", "# Échauffements\n",
"\n", "\n",
"Copier-coller ligne par ligne le programme suivant en corrigeant les éventuelles erreurs. Une fois le programme relu et corrigé, proposer puis coder une amélioration." "- [ ] Copier-coller blocspar blocs le programme suivant en corrigeant les éventuelles erreurs (il y en a au moins une par bloc)."
] ]
}, },
{ {
@ -14,7 +14,68 @@
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"\"Je veux calculer le périmètre et l'aire de cercles\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"print(\"Pour cela j'ai besoin de Pi\")\n",
"pi = 3.14\n",
"print(\"Je sais que pi vaut pi\")\n",
"print(\"Mais Python connait une valeur approchée plus précise de pi, elle vaut\", math.pi)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Je veux calculer le périmètre d'un cercle\")\n",
"rayon = 3\n",
"print(\"Quand le rayon vaut\", rayon, \"le périmètre vaut\", 2*math.pi*5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"On peut en faire une fonction\")\n",
"def perimetre(rayon)\n",
"return 4*math.pi*rayon\n",
"print(\"Le périmètre d'un cercle de rayon 2 est \", perimetre(2))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- [ ] Ecrire une fonction qui calcule l'aire d'un cercle à partir de son rayon.\n",
"- [ ] Copier-coller, tester ce bloc puis expliquer avec # ce qu'il fait."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"rayon = 10\n",
"print(\"J'ai un cercle de rayon\", rayon)\n",
"if rayon < 50:\n",
" print(\"C'est un petit cercle.\")\n",
"else:\n",
" print(\"C'est un grand cercle!\")\n",
"print(\"Son périmètre vaut\", perimetre(rayon))"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
@ -44,7 +105,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -62,20 +123,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"0.5282588961960093"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"random()" "random()"
] ]
@ -89,20 +139,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"randint(4, 10)" "randint(4, 10)"
] ]
@ -116,20 +155,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"6.374949885924709"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"uniform(4, 10)" "uniform(4, 10)"
] ]
@ -143,20 +171,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"'français'"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"# Pour définir une liste, on utilise des crochets []\n", "# Pour définir une liste, on utilise des crochets []\n",
"matieres = [\"math\", \"français\", \"Histoire\"]\n", "matieres = [\"math\", \"français\", \"Histoire\"]\n",
@ -235,13 +252,6 @@
"\n", "\n",
"À vous de simuler cette situation pour répondre à la question." "À vous de simuler cette situation pour répondre à la question."
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
@ -260,7 +270,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.7.1" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,