{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapitre 2 : \"La calculatrice Python\" - solutions\n",
    "\n",
    "---\n",
    "\n",
    "<table class=\"appbclp1\">\n",
    "<tr> <td style=\"font-weight: bold!;\">auteurs :</td><td style=\"text-align: left!;\">Laurent Pointal &lt;<a href=\"mailtp:laurent.pointal@limsi.fr\">laurent.pointal@limsi.fr</a>&gt; &amp; Bob Cordeau &lt;<a href=\"pycours@kordeo.eu\">pycours@kordeo.eu</a>&gt; </td> </tr>\n",
    "<tr> <td style=\"font-weight: bold!;\">licence :</td><td style=\"text-align: left!;\">Creative Commons Attribution-ShareAlike 4.0 International Public License (CC BY-SA 4.0) </td> </tr>\n",
    "<tr> <td style=\"font-weight: bold!;\">source :</td><td style=\"text-align: left!;\"><a href=\"https://github.com/lpointal/appbclp\">https://github.com/lpointal/appbclp</a></td> </tr>\n",
    "<tr> <td style=\"font-weight: bold!;\">description :</td><td style=\"text-align: left!;\">Les programmes dans ce Notebook Jupyter servent de support au livre <span style=\"font-style: italic!;\">« Python 3 - Apprendre à  programmer dans l'écosystème Python»</span>, édition Dunod, dans lequel les différentes sections sont expliquées </td> </tr>\n",
    "<tr> <td style=\"font-weight: bold!;\">url :</td><td style=\"text-align: left!;\"><a href=\"https://www.dunod.com/sciences-techniques/python-3\">https://www.dunod.com/EAN/9782100809141</a></td> </tr>\n",
    "</table>\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_01\n",
    "\n",
    "a, b, c = 3, 5, 7  # affectation parallèle\n",
    "\n",
    "print(\"a-b/c =\", a-b/c)\n",
    "print(\"(a-b)/c =\", (a-b)/c)\n",
    "print(\"a/b/c =\", a/b/c)\n",
    "print(\"a/b*c =\", a/b*c)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_02\n",
    "\n",
    "L'expression d'un angle en degrés, minutes secondes correspond à une expression en degrés décimaux (un tour de cercle fait 360°) dans laquelle la partie décimale a été découpée en minutes ($\\frac{1}{60}°$) et secondes ($\\frac{1}{3600}°$).\n",
    "\n",
    "Dans l'expression d'un angle en radians, un tour complet fait $2 \\pi\\, rad$. Un degré correspond donc à $1°=\\frac{360}{2 \\pi}\\,rad=\\frac{180}{\\pi}\\,rad$, ou encore $1\\,rad = \\frac{\\pi}{180}°$.\n",
    "\n",
    "On commence par calculer l'angle en degrés décimaux, puis on convertit celui-ci en radians.\n",
    "\n",
    "Pour la conversion dans l'autre sens, il serait possible d'exprimer l'opération mathématique inverse, on a choisi de présenter dans la correction la fonction standard `math.degrees()` de Python (il existe aussi `math.radians()`) qui permet de réaliser cette conversion. Il faut ensuite extraire de la partie décimale le nombre de minutes, puis exprimer ce qu'il reste en nombre de secondes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_02\n",
    "\n",
    "import math\n",
    "\n",
    "# programme principal ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
    "print(\"Entrez un angle en degres, minutes, secondes\")\n",
    "d = float(input(\"\\tdegres : \"))    # ne pas oublier de transtyper \n",
    "m = float(input(\"\\tminutes : \"))   # les saisies str -> float\n",
    "s = float(input(\"\\tsecondes : \"))\n",
    "total_degres = d + m / 60 + s / 3600\n",
    "rad = total_degres * (math.pi / 180)\n",
    "print(\"En radians :\", rad)\n",
    "\n",
    "rad = float(input(\"\\nEntrez un angle en radians : \"))\n",
    "angD = math.degrees(rad) \n",
    "dd = int(angD)\n",
    "mm = int(60*(angD-dd))\n",
    "ss = 60*(60*(angD-dd)-mm)\n",
    "print(\"\\tdegres :\", dd)\n",
    "print(\"\\tminutes :\", mm)\n",
    "print(\"\\tsecondes :\", ss)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_03"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Entrez une température en degrés Celsius : 20\n",
      "\t 20.00 °C ==> 68.00 °F\n",
      "\t 20.00 °C ==> 68.00 °F\n",
      "\n",
      "Entrez une température en degrés Fahrenheit : 68\n",
      "\t 68.00 °F ==> 20.00 °C\n",
      "\t 68.00 °F ==> 20.00 °C\n"
     ]
    }
   ],
   "source": [
    "# exo02_03\n",
    "\n",
    "t_C = float(input(\"Entrez une température en degrés Celsius : \"))\n",
    "t_F = (1.8*t_C) + 32\n",
    "print(f\"\\t {t_C:.2f} °C ==> {t_F:.2f} °F\")\n",
    "\n",
    "t_F = float(input(\"\\nEntrez une température en degrés Fahrenheit : \"))\n",
    "t_C = (t_F - 32) / 1.8\n",
    "print(f\"\\t {t_F:.2f} °F ==> {t_C:.2f} °C\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_04\n",
    "\n",
    "Pour faire le test sur les côtés du triangle, il est aussi possible d'utiliser une astuce :\n",
    "```python\n",
    "cotes = sorted((a, b, c))   # trie les 3 côtés par ordre croissant\n",
    "if cotes[0] + cotes[1] > cotes[2]:\n",
    "    …\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Entrez les longueurs des trois côtés\n",
      "\ta : 3\n",
      "\tb : 4\n",
      "\tc : 5\n",
      "Périmètre = 12.00 \t Aire = 6.00\n"
     ]
    }
   ],
   "source": [
    "# exo02_04\n",
    "\n",
    "from math import sqrt\n",
    "\n",
    "# programme principal -----------------------------------------------\n",
    "print(\"Entrez les longueurs des trois côtés\")\n",
    "a = float(input(\"\\ta : \"))\n",
    "b = float(input(\"\\tb : \"))\n",
    "c = float(input(\"\\tc : \"))\n",
    "\n",
    "# le problème n'est possible que si la longueur de chaque côté est \n",
    "# inférieure à la somme des deux autres - sinon ce n'est pas un\n",
    "# triangle :\n",
    "if (a < b+c) and (b < a+c) and (c < a+b):\n",
    "    d = (a+b+c)/2                  # demi-périmètre\n",
    "    s = sqrt(d*(d-a)*(d-b)*(d-c))  # aire\n",
    "    print(f\"Périmètre = {2*d:.2f} \\t Aire = {s:.2f}\")\n",
    "else:\n",
    "    print(\"Problème impossible !\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_05"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_05\n",
    "\n",
    "s = input(\"Entrez une chaîne de caractères : \")\n",
    "c = input(\"Entrez un caractère à insérer : \")\n",
    "\n",
    "print(\"\\n\" + c[0].join(s))  # la méthode join() accepte tout argument itérable"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_06\n",
    "\n",
    "Lorsqu'on exécute le script de correction, pour une hauteur de 300 m on obtient une période de 34,7461 s."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Entrez la longueur du pendule (m) : 300\n",
      "Période du pendule : 34.7461 s\n",
      "Période du pendule : 34.7461 s\n"
     ]
    }
   ],
   "source": [
    "# exo02_06\n",
    "\n",
    "from math import sqrt, pi\n",
    "\n",
    "# Constante\n",
    "G = 9.81\n",
    "\n",
    "# Programme principal -----------------------------------------------\n",
    "longueur = float(input(\"Entrez la longueur du pendule (m) : \"))\n",
    "\n",
    "print(f\"Période du pendule : {(2*pi*sqrt(longueur/G)):g} s\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_07\n",
    "\n",
    "Pour une vitesse de 1 mph on obtient une vitesse de 1,609 km/h, soit 0,446944 m/s ou encore 0,86879 noeuds."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Entrez le nombre de miles parcourus en une heure : 1\n",
      "\n",
      " 1 mph = 1.609 km/h = 0.446944 m/s = 0.86879 noeuds\n"
     ]
    }
   ],
   "source": [
    "# exo02_07\n",
    "\n",
    "mph = float(input(\"Entrez le nombre de miles parcourus en une heure : \"))\n",
    "\n",
    "# convertions\n",
    "mps = mph * 1609 / 3600  # en m/s\n",
    "kmph = mph * 1.609       # en km/h\n",
    "noeud = kmph / 1.852     # en noeuds\n",
    "\n",
    "print(f\"\\n {mph:g} mph = {kmph:g} km/h = {mps:g} m/s = {noeud:g} noeuds\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_08"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Entrez les longueurs des trois côtes\n",
      "\ta : 3\n",
      "\tb : 4\n",
      "\tc : 5\n",
      "Ces trois côtés déterminent bien un triangle\n",
      "Ce triangle est rectangle.\n"
     ]
    }
   ],
   "source": [
    "# exo02_08\n",
    "\n",
    "print(\"Entrez les longueurs des trois côtes\")\n",
    "a = float(input(\"\\ta : \"))\n",
    "b = float(input(\"\\tb : \"))\n",
    "c = float(input(\"\\tc : \"))\n",
    "\n",
    "# le problème n'est possible que si la longueur de chaque côté \n",
    "# est inférieure à la somme des deux autres :\n",
    "if (a < b+c) and (b < a+c) and (c < a+b):\n",
    "    print(\"Ces trois côtés déterminent bien un triangle\")\n",
    "    # pour afficher \"triange quelconque\" en l'abscence des autres cas,\n",
    "    # on utilise une variable drapeau\n",
    "    quelconque = True  \n",
    "    \n",
    "    if (a == b == c):  # trois côtés égaux\n",
    "        print(\"Ce triangle est équilatéral.\")\n",
    "        quelconque = False\n",
    "    elif (a == b) or (b == c) or (c == a):  # deux côtés égaux\n",
    "        print(\"Ce triangle est isocèle.\")\n",
    "        quelconque = False\n",
    "        \n",
    "    if (a*a + b*b == c*c)  or  (b*b + c*c == a*a)  or  (c*c + a*a == b*b):\n",
    "        print(\"Ce triangle est rectangle.\")\n",
    "        quelconque = False\n",
    "        \n",
    "    if quelconque:\n",
    "        print(\"Ce triangle est quelconque.\")\n",
    "    \n",
    "else:\n",
    "    print(\"Ces trois côtés ne forment pas un triangle !\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_09\n",
    "\n",
    "Lorsqu'on exécute le script de correction, pour une durée de 10<sup>8</sup> secondes, on obtiens: 3 annees de 365 jours, 2 mois de 30 jours, 2 jours, 9 heures, 46 minutes et 40 secondes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nombre de secondes : 1e8\n",
      "\n",
      " 100000000 secondes correspondent à :\n",
      "\t 3.0 annees de 365 jours\n",
      "\t 2.0 mois de 30 jours\n",
      "\t 2.0 jours\n",
      "\t 9.0 heures\n",
      "\t 46.0 minutes\n",
      "\t 40.0 secondes\n"
     ]
    }
   ],
   "source": [
    "# exo02_09\n",
    "\n",
    "# programme principal -----------------------------------------------\n",
    "nspj = 60*60*24      # secondes par jour\n",
    "nspm = nspj*30       # secondes par mois de 30 jours\n",
    "nspa = nspj*365      # secondes par annee de 365 jours\n",
    "nsd = float(input(\"Nombre de secondes : \"))\n",
    "\n",
    "# on utilise divmod(a, b) qui retourne le tuple (quotient, reste)\n",
    "na, nsr = divmod(nsd, nspa)   # nb annees, secondes restantes\n",
    "nmo, nsr = divmod(nsr, nspm)  # nb mois, secondes restantes\n",
    "nj, nsr = divmod(nsr, nspj)   # nb jours, secondes restantes\n",
    "nh, nsr = divmod(nsr, 3600)   # nb heures, secondes restantes\n",
    "nmi, nsr = divmod(nsr, 60)    # nb minutes, secondes restantes\n",
    "\n",
    "print(f\"\\n {int(nsd)} secondes correspondent à :\")\n",
    "print(\"\\t\", na, \"annees de 365 jours\")\n",
    "print(\"\\t\", nmo, \"mois de 30 jours\")\n",
    "print(\"\\t\", nj, \"jours\")\n",
    "print(\"\\t\", nh, \"heures\")\n",
    "print(\"\\t\", nmi, \"minutes\")\n",
    "print(\"\\t\", nsr, \"secondes\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_10\n",
    "\n",
    "Pour une année non bissextile, on trouve une erreur relative de l'expression d'une année en nombre de secondes de 0,38 % (estimé à 31415926 par rapport à 31536000)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Erreur relative : 0.0038\n"
     ]
    }
   ],
   "source": [
    "# exo02_10\n",
    "\n",
    "from math import pi\n",
    "\n",
    "# programme principal -----------------------------------------------\n",
    "nspab = 60*60*24*365  # secondes par année non bissextile\n",
    "print(f\"Erreur relative : {abs((nspab - pi*1e7)/nspab):.4f}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saisie de v1\n",
      "\tabscisse : 1\n",
      "\tordonnée : 2\n",
      "\thauteur : 3\n",
      "\n",
      "Saisie de v2\n",
      "\tabscisse : 4\n",
      "\tordonnée : 5\n",
      "\thauteur : 6\n",
      "\n",
      "Produit scalaire : 32 \n",
      " cosinus : 0.0296846\n",
      "\n",
      "Produit scalaire : 32 \n",
      " cosinus : 0.0296846\n"
     ]
    }
   ],
   "source": [
    "# exo02_11\n",
    "\n",
    "# initialisations (utilise l'opérateur de répétition)\n",
    "v, w = [0.0]*3, [0.0]*3   \n",
    "\n",
    "print(\"Saisie de v\")\n",
    "v[0] = float(input(\"\\tabscisse : \"))\n",
    "v[1] = float(input(\"\\tordonnée : \"))\n",
    "v[2] = float(input(\"\\thauteur : \"))\n",
    "\n",
    "print(\"\\nSaisie de w\")\n",
    "w[0] = float(input(\"\\tabscisse : \"))\n",
    "w[1] = float(input(\"\\tordonnée : \"))\n",
    "w[2] = float(input(\"\\thauteur : \"))\n",
    "\n",
    "# produit scalaire\n",
    "ps = v[0]*w[0] + v[1]*w[1] + v[2]*w[2]\n",
    "\n",
    "# normes\n",
    "nv = v[0]**2 + v[1]**2 + v[2]**2\n",
    "nw = w[0]**2 + w[1]**2 + w[2]**2\n",
    "\n",
    "# affichage\n",
    "print(f\"\\nProduit scalaire : {ps:g} \\n cosinus : {ps/(nv*nw):g}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saisie de v\n",
      "\tabscisse : 1\n",
      "\tordonnée : 2\n",
      "\thauteur : 3\n",
      "\n",
      "Saisie de w\n",
      "\tabscisse : 4\n",
      "\tordonnée : 5\n",
      "\thauteur : 6\n",
      "\n",
      "Produit vectoriel : [-3, 6, -3]\n",
      "\n",
      "Produit vectoriel : [(-3.0, 6.0, -3.0)]\n",
      "sinus : 0.0500928\n"
     ]
    }
   ],
   "source": [
    "# exo02_12\n",
    "\n",
    "# initialisations (utilise l'opérateur de répétition)\n",
    "v, w, pv = [0.0]*3, [0.0]*3, [0.0]*3\n",
    "\n",
    "print(\"Saisie de v\")\n",
    "v[0] = float(input(\"\\tabscisse : \"))\n",
    "v[1] = float(input(\"\\tordonnée : \"))\n",
    "v[2] = float(input(\"\\thauteur : \"))\n",
    "\n",
    "print(\"\\nSaisie de w\")\n",
    "w[0] = float(input(\"\\tabscisse : \"))\n",
    "w[1] = float(input(\"\\tordonnée : \"))\n",
    "w[2] = float(input(\"\\thauteur : \"))\n",
    "\n",
    "# produit vectoriel\n",
    "pv[0] = v[1]*w[2] - w[1]*v[2]\n",
    "pv[1] = v[2]*w[0] - w[2]*v[0]\n",
    "pv[2] = v[0]*w[1] - w[0]*v[1]\n",
    "\n",
    "# normes\n",
    "nv = v[0]**2 + v[1]**2 + v[2]**2\n",
    "nw = w[0]**2 + w[1]**2 + w[2]**2\n",
    "npv = pv[0]**2 + pv[1]**2 + pv[2]**2\n",
    "\n",
    "# affichages\n",
    "print(f\"\\nProduit vectoriel : [{pv[0], pv[1], pv[2]}]\")\n",
    "print(\"sinus : %g\" % (npv/(nv*nw)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_13\n",
    "\n",
    "dna = \"tgaattctatgaatggactgtcccaaagaagtagggacccac\"\n",
    "\n",
    "# à faire dans l'ordre !\n",
    "# on utilise une lettre \"temporaire\" _ qui n'est pas dans la chaîne\n",
    "dna = dna.replace('t', '_')\n",
    "dna = dna.replace('a', 't')\n",
    "dna = dna.replace('_', 'g')\n",
    "\n",
    "print(dna)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_14\n",
    "\n",
    "s = \"abcababc\"\n",
    "\n",
    "nb_a = s.count('a')\n",
    "s = 'a' * nb_a + s.replace('a', '')\n",
    "\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_15\n",
    "\n",
    "s = \"abcababc\"\n",
    "\n",
    "nb_a = s.count('a')\n",
    "s = s.replace('a', '') + str(nb_a)\n",
    "\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_16\n",
    "\n",
    "z1, z2 = -1 + 2j, 3 + 4j\n",
    "\n",
    "print(z1 + z2)\n",
    "print(z1 - z2)\n",
    "print(z1 - 3*z2)\n",
    "print(z1 * z2)\n",
    "print(z1 / z2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_17\n",
    "\n",
    "print(1 / (4 + 2j))\n",
    "print((2 / (1 - 1j)) - (5 / (1 + 1j)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# exo02_18\n",
    "\n",
    "adn = \"tgaattctatgaatggactgtcccaaagaagtagggacccac\"\n",
    "dna = adn[::-1]\n",
    "\n",
    "print(f\"dna : '{adn}' \\n est un palindrome de \\nadn : '{dna}'\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_19"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Vitesse = 2.8583865351131745\n",
      "Vitesse = 2.9 m/s\n"
     ]
    }
   ],
   "source": [
    "# exo02_19\n",
    "\n",
    "t = 6.892  # temps (s)\n",
    "d = 19.7   # distance (m)\n",
    "\n",
    "print('Vitesse =', d/t)\n",
    "# amélioration\n",
    "print(f'Vitesse = {d/t:.1f} m/s')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### exo02_20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Résistance équivalente en série : 200 ohms\n",
      "Résistance équivalente en parallèle : 50.0 ohms\n"
     ]
    }
   ],
   "source": [
    "# exo02_20\n",
    "\n",
    "R1, R2 = 100, 100\n",
    "\n",
    "Rs = R1 + R2\n",
    "Rp = (R1*R2) / (R1+R2)\n",
    "\n",
    "# si R1 = R2 = R, alors Req_série = 2*R et Req_parallèle = R/2\n",
    "print(f'Résistance équivalente en série : {Rs} ohms')\n",
    "print(f'Résistance équivalente en parallèle : {Rp} ohms')"
   ]
  }
 ],
 "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.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
