python:les_boucles

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
python:les_boucles [2019/10/20 14:30] – [For avec Range] physixpython:les_boucles [2020/07/24 03:31] (Version actuelle) – modification externe 127.0.0.1
Ligne 3: Ligne 3:
 ===== While ===== ===== While =====
  
-<code>+<code python>
 i = 0 i = 0
 while i <= 10 : while i <= 10 :
Ligne 35: Ligne 35:
 =====   ===== =====   =====
  
-<code>+<code python>
 s = "Hello world" s = "Hello world"
  
Ligne 44: Ligne 44:
 donne : donne :
  
-<file>>>>+<file> 
 +>>>
 H H
 e e
Ligne 60: Ligne 61:
 ==== For avec Range ==== ==== For avec Range ====
  
-<code>+<code python>
 for i in range(0,10) : for i in range(0,10) :
     print(i)     print(i)
Ligne 82: Ligne 83:
 </file> </file>
  
-<code>+<code python>
 for i in range(2,10,3): for i in range(2,10,3):
     print(i)     print(i)
Ligne 88: Ligne 89:
 </code> </code>
  
-donne+{{url>https://pythontutor.com/iframe-embed.html#code=for%20i%20in%20range%282,10,3%29%3A%0A%20%20%20%20print%28i%29&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=nevernest&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false}}
  
-<code> +<code python
-+x = [0., 0.1, 0.2, 0.3, 0.4, 0.5] 
-+y = [ ] 
-8+ 
 +for i in range( len( x ) ): #i est un int, c'est un indice 
 +    y.append( x[ i ] ** 2 + 4. ) 
 + 
 +print(y) 
 + 
 +</code> 
 + 
 +{{url>https://pythontutor.com/iframe-embed.html#code=x%20%3D%20%5B0.,%200.1,%200.2,%200.3,%200.4,%200.5%5D%0Ay%20%3D%20%5B%20%5D%0A%0Afor%20i%20in%20range%28%20len%28%20x%20%29%20%29%3A%20%23i%20est%20un%20int,%20c'est%20un%20indice%0A%20%20%20%20y.append%28%20x%5B%20i%20%5D%20**%202%20%2B%204.%20%29%0A%20%20%20%20%0Aprint%28y%29&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=nevernest&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false}} 
 + 
 +<code python> 
 +x = [0., 0.1, 0.2, 0.3, 0.4, 0.5] 
 +y = [ ] 
 + 
 +for i in x:  #i est un float, c'est un élément de x 
 +    y.append( i ** 2 + 4. ) 
 + 
 +print(y) 
 + 
 +</code> 
 + 
 +{{url>https://pythontutor.com/iframe-embed.html#code=x%20%3D%20%5B0.,%200.1,%200.2,%200.3,%200.4,%200.5%5D%0Ay%20%3D%20%5B%20%5D%0A%0Afor%20i%20in%20x%3A%20%20%23i%20est%20un%20float,%20c'est%20un%20%C3%A9l%C3%A9ment%20de%20x%0A%20%20%20%20y.append%28%20i%20**%202%20%2B%204.%20%29%0A%0Aprint%28y%29&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=nevernest&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false}} 
 + 
 +<code python> 
 +x = [0., 0.1, 0.2, 0.3, 0.4, 0.5] 
 +y = [ i ** 2 + 4. for i in x] 
 + 
 +print(y)
  
 </code> </code>
  
-{{url>http://pythontutor.com/iframe-embed.html#code=for%20i%20in%20range%282,10,3%29%3A%0A%20%20%20%20print%28i%29&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=nevernest&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false}}+{{url>https://pythontutor.com/iframe-embed.html#code=x%20%3D%20%5B0.,%200.1,%200.2,%200.3,%200.4,%200.5%5D%0Ay%20%3D%20%5B%20i%20**%202%20%2B%204.%20for%20i%20in%20x%5D%0A%0Aprint%28y%29&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=nevernest&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false}}
  
  
 ==== For avec Break ==== ==== For avec Break ====
  
-<code>+<code python>
 for i in range(0,10) : for i in range(0,10) :
     print(i)     print(i)
Ligne 111: Ligne 139:
 donne : donne :
  
-<file>>>>+<file> 
 +>>>
 0 0
 1 1
  • python/les_boucles.1571574635.txt.gz
  • Dernière modification : 2020/07/24 00:23
  • (modification externe)