.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gyexamples/plot_simple_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gyexamples_plot_simple_example.py: .. _l-example-one: Quelques examples simples ========================= .. contents:: :local: Case 1 ++++++ Que calcule le programme suivant ? .. GENERATED FROM PYTHON SOURCE LINES 18-30 .. code-block:: default res = [[1]] for i in range(1, 10): row = [1] for j in range(1, i): n = sum(res[-1][j - 1: j + 1]) row.append(n) row.append(1) res.append(row) print(res) .. rst-class:: sphx-glr-script-out .. code-block:: none [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]] .. GENERATED FROM PYTHON SOURCE LINES 31-32 Un autre affichage peut peut-ĂȘtre aider. .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: default import pprint pprint.pprint(res) .. rst-class:: sphx-glr-script-out .. code-block:: none [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]] .. GENERATED FROM PYTHON SOURCE LINES 39-41 Case 2 ++++++ .. GENERATED FROM PYTHON SOURCE LINES 41-66 .. code-block:: default import cProfile nombres = [9, 7, 5, 4, 6, 7, 3, 1, 7, 8] def moyenne(ens): return sum(ens) / len(ens) def ecarttype(ens): var = [(n - moyenne(ens)) ** 2 for n in ens] return (sum(var) / len(var)) ** 0.5 print(moyenne(nombres)) print(ecarttype(nombres)) with cProfile.Profile() as pr: for n in range(100000): ecarttype(nombres) pr.print_stats() .. rst-class:: sphx-glr-script-out .. code-block:: none 5.7 2.3259406699226015 3400002 function calls in 5.596 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 cProfile.py:117(__exit__) 1000000 1.412 0.000 2.829 0.000 plot_simple_example.py:47(moyenne) 100000 0.547 0.000 5.596 0.000 plot_simple_example.py:51(ecarttype) 100000 2.028 0.000 4.857 0.000 plot_simple_example.py:52() 1100000 0.395 0.000 0.395 0.000 {built-in method builtins.len} 1100000 1.214 0.000 1.214 0.000 {built-in method builtins.sum} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} .. GENERATED FROM PYTHON SOURCE LINES 67-69 Case 3 ++++++ .. GENERATED FROM PYTHON SOURCE LINES 69-81 .. code-block:: default def bizarre(ensemble): # premier zero ensemble.append(0) for i in range(len(ensemble)): if ensemble[i] == 0: return i res = [1, 4, 5] print("bizarre=", bizarre(res)) print("res=", res) .. rst-class:: sphx-glr-script-out .. code-block:: none bizarre= 3 res= [1, 4, 5, 0] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 5.952 seconds) .. _sphx_glr_download_gyexamples_plot_simple_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_simple_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_simple_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_