Feat(Programmation): Fin du tp simulation en python
This commit is contained in:
parent
6b3140bbc2
commit
9c2a314a6c
|
@ -13116,7 +13116,9 @@ div#notebook {
|
|||
<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">
|
||||
<h1 id="Échauffements">Échauffements<a class="anchor-link" href="#Échauffements">¶</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="Échauffements">Échauffements<a class="anchor-link" href="#Échauffements">¶</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>
|
||||
|
@ -13126,7 +13128,85 @@ div#notebook {
|
|||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class=" highlight hl-ipython3"><pre><span></span>
|
||||
<div class=" highlight hl-ipython3"><pre><span></span><span class="s2">"Je veux calculer le périmètre et l'aire de cercles"</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 [ ]:</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">"Pour cela j'ai besoin de Pi"</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">"Je sais que pi vaut pi"</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s2">"Mais Python connait une valeur approchée plus précise de pi, elle vaut"</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 [ ]:</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">"Je veux calculer le périmètre d'un cercle"</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">"Quand le rayon vaut"</span><span class="p">,</span> <span class="n">rayon</span><span class="p">,</span> <span class="s2">"le périmètre vaut"</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 [ ]:</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">"On peut en faire une fonction"</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">"Le périmètre d'un cercle de rayon 2 est "</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 [ ]:</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">"J'ai un cercle de rayon"</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"><</span> <span class="mi">50</span><span class="p">:</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s2">"C'est un petit cercle."</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">"C'est un grand cercle!"</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s2">"Son périmètre vaut"</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>
|
||||
|
||||
</div>
|
||||
|
@ -13160,7 +13240,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [20]:</div>
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13184,7 +13264,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [21]:</div>
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<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 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 class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
|
||||
</div><div class="inner_cell">
|
||||
|
@ -13227,7 +13287,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [22]:</div>
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13237,26 +13297,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</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 class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
|
||||
</div><div class="inner_cell">
|
||||
|
@ -13270,7 +13310,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [23]:</div>
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13280,26 +13320,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</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 class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
|
||||
</div><div class="inner_cell">
|
||||
|
@ -13313,7 +13333,7 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [26]:</div>
|
||||
<div class="prompt input_prompt">In [ ]:</div>
|
||||
<div class="inner_cell">
|
||||
<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>
|
||||
|
@ -13326,26 +13346,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
</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>'français'</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">
|
||||
|
@ -13412,19 +13412,6 @@ Lorsque l'outil de simulation utilise un ordinateur on parle de simulation numé
|
|||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="prompt input_prompt">In [ ]:</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>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"source": [
|
||||
"# Échauffements\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,
|
||||
"metadata": {},
|
||||
"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",
|
||||
|
@ -44,7 +105,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -62,20 +123,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.5282588961960093"
|
||||
]
|
||||
},
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"random()"
|
||||
]
|
||||
|
@ -89,20 +139,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"8"
|
||||
]
|
||||
},
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"randint(4, 10)"
|
||||
]
|
||||
|
@ -116,20 +155,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"6.374949885924709"
|
||||
]
|
||||
},
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"uniform(4, 10)"
|
||||
]
|
||||
|
@ -143,20 +171,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'français'"
|
||||
]
|
||||
},
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Pour définir une liste, on utilise des crochets []\n",
|
||||
"matieres = [\"math\", \"français\", \"Histoire\"]\n",
|
||||
|
@ -235,13 +252,6 @@
|
|||
"\n",
|
||||
"À vous de simuler cette situation pour répondre à la question."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
@ -260,7 +270,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.7.1"
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
Loading…
Reference in New Issue