Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
apprendre à programmer
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Nov 11, 2014
1 parent bea738a commit afaf514
Show file tree
Hide file tree
Showing 12 changed files with 838 additions and 3 deletions.
89 changes: 89 additions & 0 deletions _doc/notebooks/premierspas/pp_exo_deviner_un_nombre.ipynb
@@ -0,0 +1,89 @@
{
"metadata": {
"name": "",
"signature": "sha256:4291930ae5a00c88259a610b5f611a227a10ddada4ef754dae7c8bd8aa3811e0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Deviner un nombre al\u00e9atoire"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1 :** Ecrire une jeu dans lequel python choisi al\u00e9atoirement un nombre entre 0 et 100, et essayer de trouver ce nombre en 10 \u00e9tapes (avec la fonction [open_window_params](http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/pyquickhelper/funcwin/frame_params.html?highlight=open#pyquickhelper.funcwin.frame_params.open_window_params))."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from pyquickhelper import open_window_params\n",
"def demande_nombre(appreciation):\n",
" params = { \"nombre\":\"\" }\n",
" ans = open_window_params (params, title=\"Entrez un nombre\", \n",
" help_string = appreciation, \n",
" key_save=\"alean\")\n",
" nb = int( ans[\"nombre\"] ) \n",
" return nb\n",
"nb = demande_nombre(\"?\")\n",
"nb"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"7"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** Q2 :** Transformer ce jeu en une fonction ``jeu(nVies)`` o\u00f9 ``nVies`` est le nombre d'it\u00e9rations maximum."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q3 : ** Adapter le code pour faire une classe joueur avec une m\u00e9thode jouer, o\u00f9 un joueur est d\u00e9fini par un pseudo et son nombre de vies. Faire jouer deux joueurs et d\u00e9terminer le vainqueur."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}

0 comments on commit afaf514

Please sign in to comment.