Permalink
Browse files

ajout d'un notebook sur tutormagic

  • Loading branch information...
sdpython committed Jun 19, 2015
1 parent 9c617eb commit c30ccad5b4b81490ba92da928075cb4397d3d106
Showing with 105 additions and 0 deletions.
  1. +105 −0 _doc/notebooks/exemples/visualiser_avec_tutormagic.ipynb
@@ -0,0 +1,105 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Visualiser son code Python avec tutormagic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Le site [pythontutor](http://www.pythontutor.com/) permet de visualiser pas à pas l'exécution de son code. Le moduler [tutormagic](https://pypi.python.org/pypi/tutormagic) permet de faire cela depuis un notebook. On charge d'abord l'extension."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%load_ext tutormagic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Puis on visualise l'exécution de codequi se contente de faire passer le plus petit élément du tableau en première position. "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"90%\"\n",
" height=\"350\"\n",
" src=\"http://pythontutor.com/iframe-embed.html#code=%0Aa%20%3D%20%5B6%2C5%2C7%2C3%2C7%2C3%2C1%5D%0Afor%20i%20in%20range%281%2Clen%28a%29%29%3A%0A%20%20%20%20if%20a%5B0%5D%20%3E%20a%5Bi%5D%3A%0A%20%20%20%20%20%20%20%20ech%20%3D%20a%5B0%5D%20%0A%20%20%20%20%20%20%20%20a%5B0%5D%20%3D%20a%5Bi%5D%0A%20%20%20%20%20%20%20%20a%5Bi%5D%20%3D%20ech&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=3&rawInputLstJSON=%5B%5D&curInstr=0&codeDivWidth=50%25&codeDivHeight=100%25\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x6f4b7f0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%tutor --lang python3\n",
"\n",
"a = [6,5,7,3,7,3,1]\n",
"for i in range(1,len(a)):\n",
" if a[0] > a[i]:\n",
" ech = a[0] \n",
" a[0] = a[i]\n",
" a[i] = ech"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit c30ccad

Please sign in to comment.