{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercices du livre - Chapitre 2 - 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": [
    "### Exercice 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 12  # Essayer avec différentes valeurs de a\n",
    "\n",
    "a >= 10 and a <=20\n",
    "# ou, plus lisible :\n",
    "10 <= a <= 20"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercice 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercice 2\n",
    "\n",
    "# Import ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
    "from math import pi\n",
    "\n",
    "# Programme principal =========================================================\n",
    "rayon = float(input(\"Rayon de la base du cône (m) : \"))\n",
    "hauteur = float(input(\"Hauteur du cône (m) : \"))\n",
    "\n",
    "volume = (pi*rayon*rayon*hauteur) / 3.0\n",
    "print(\"Volume du cône =\", volume, \"m3\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercice 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercice 3\n",
    "\n",
    "v = int(input('Valeur de v : '))\n",
    "nb_essais = 4\n",
    "nb_essais < 5 and (v <= 0 or v >= 100 or v % 3 != 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercice 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercice 4\n",
    "\n",
    "s = \"Dark side of the moon\"\n",
    "s.title().center(60, '=')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercice 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercice 5\n",
    "\n",
    "HA_PAR_KM2 = 100  # convertion hectare <=> kilomètre carré\n",
    "\n",
    "print(\"Aire d'un champ :\")\n",
    "longueur = float(input('\\tLongueur (hm) : '))\n",
    "largeur = float(input('\\tlargeur (hm) : '))\n",
    "\n",
    "ha = longueur * largeur\n",
    "\n",
    "print(f\"\\nAire du champ : {ha} ha, soit {ha / HA_PAR_KM2} km2.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercice 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Exercice 6\n",
    "\n",
    "SECONDES_PAR_MINUTE = 60\n",
    "SECONDES_PAR_HEURE  = 3_600\n",
    "SECONDES_PAR_JOUR   = 86_400\n",
    "\n",
    "# Saisie\n",
    "secondes = int(input(\"Nombre de secondes : \"))\n",
    "\n",
    "jours, secondes = divmod(secondes, SECONDES_PAR_JOUR)\n",
    "heures, secondes = divmod(secondes, SECONDES_PAR_HEURE)\n",
    "minutes, secondes = divmod(secondes, SECONDES_PAR_MINUTE)\n",
    "\n",
    "print(f\"\\nDurée : [{jours:d}:{heures:02d}:{minutes:02d}:{secondes:02d}]\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
