---
---

<link rel="stylesheet" href="styles.css" type="text/css">

<span id="Initial"><br><br></span>

# <span><a href="#Introduction">[&nabla;]</a></span> <span><a href="#Final">[@]</a></span> <span style="color: red;">Introduction à Python 3<br><br></span>

### Version 2022-10-25
### Licence cc-by-sa ModLibre.info sauf autres indications

#### NB : Copiez les instructions que vous voulez tester dans une version récente de Python 3


<span id="Introduction"><br><br></span>

# <span><a href="#Plan">[&nabla;]</a></span> <span><a href="#Initial">[&Delta;]</a></span> <span style="color: red;">Programmes OLPC traduits en Python 3<br><br></span>

### Le projet [OLPC](https://fr.wikipedia.org/wiki/One_Laptop_per_Child) (One Laptop per Child) a été lancé en 2005 pour développer «&nbsp;un ordinateur portable pour chaque enfant&nbsp;».
### Ce projet a suivi l'évolution des technologies et a permis de créer des logiciels éducatifs libres utilisables sur les portables et les tablettes modernes.
### L'essentiel de ces objectifs sont repris par la plateforme [Sugarizer](https://sugarizer.org/).

### La plupart des applications OLPC originales avaient été développées en Python 2 et sont disponibles sur le [Wiki d'OLPC](https://wiki.laptop.org/go/Pippy).
### On trouvera ci-dessous une sélection de ces applications traduites en Python 3.


<span id="Plan"><br><br></span>

# <span><a href="#Maths">[&nabla;]</a></span> <span><a href="#Initial">[&Delta;]</a></span> <span style="color: red;">Liste des programmes OLPC traduits en Python 3<br><br></span>

### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Maths) [**Exercices mathématiques simples**](#Maths)
### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Multiple) [**Multiplication**](#Multiple)
### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Fibonacci) [**Suite de Fibonacci**](#Fibonacci)
### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Pythagoras) [**Théorème de Pythagore**](#Pythagoras)
### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Pascal) [**Triangle de Pascal**](#Pascal)
### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Sierpinsky) [**Triangle de Sierpinsky**](#Sierpinsky)
### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Guess) [**Devine un nombre**](#Guess)
### &#x25cf; &nbsp;&nbsp;&nbsp;&nbsp; [[&nabla;]](#Gym) [**Gymnastique**](#Gym)

<span id="Maths"><br><br></span>

# <span><a href="#Multiple">[&nabla;]</a></span> <span><a href="#Plan">[&Delta;]</a></span> <span><a href="#Plan">[@]</a> </span> <span style="color: red;">Maths</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   Madeleine Ball
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-09-29 Jean.Thiery@ModLibre.info
#
# Title:          Apples (-> Pommes)
# Author:         Madeleine Ball
# About:          Adding and dividing
# Shows:          Print Statements and Basic Math
# XOversion:  --> Bundled in 656 ?

print ("Let's do math!")
print ("On Monday I picked 22 apples. On Tuesday I picked 12.")
print ("Now I have: ", 22 + 12)

print ("My brother says he picked twice as many apples last week.")
print ("This means he picked: ", (22 + 12) * 2)

print ("I have 3 friends to whom I would like to give apples.")
print ("One third of my apples is about: ", (22 + 12) // 3)
print ("Or, more exactly: ", (22.0 + 12.0) / 3.0)

# Initial version in Python 2 ##########################################
# Title:          Apples
# Author:         Rafael Ortiz
# About:          The Fibonacci Number Series
# Shows:          Using tuple assignments. While loop.
# XOversion:      Bundled in 656
#
# Author:         Madeleine Ball
# About:          Adding and dividing
# Shows:          Print Statements and Basic Math
# XOversion:      Bundled in 656
#
#   print "Let's do math!"
#   print "On Monday I picked 22 apples. On Tuesday I picked 12."
#   print "Now I have: ", 22 + 12
#
#   print "My brother says he picked twice as many apples last week."
#   print "This means he picked: ", (22 + 12) * 2
#
#   print "I have 3 friends to whom I would like to give apples."
#   print "One third of my apples is about: ", (22 + 12) // 3
#   print "Or, more exactly: ", (22.0 + 12.0) / 3.0```
```
```
Let's do math!
On Monday I picked 22 apples. On Tuesday I picked 12.
Now I have: 34

My brother says he picked twice as many apples last week.
This means he picked: 68

I have 3 friends to whom I would like to give apples.
One third of my apples is about: 11
Or, more exactly: 11.333333
```


<span id="Multiple"><br><br></span>

# <span><a href="#Fibonacci">[&nabla;]</a></span> <span><a href="#Maths">[&Delta;]</a></span> <span><a href="#Plan">[@]</a> </span> <span style="color: red;">Multiplication</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   Chris Ball
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-09-29 Jean.Thiery@ModLibre.info
#
# Title:          Times2
# Author:         Chris Ball
# About:          Print any times table
# Shows:          Loops, range, and input
# XOversion:  --> Bundled in 656 ?

number = int(input("Which times table? "))
for i in range(1,13):
	print(i, "x", number, "=", i*number)

# Initial version in Python 2 ##########################################
# Title:          Times2
# Author:         Chris Ball
# About:          Print any times table
# Shows:          Loops, range, and input
# XOversion:      Bundled in 656
#
#   number = input("Which times table? ")
#   for i in range(1,13):
#       print i, "x", number, "=", i*number
```
```
Which times table? 7
1 x 7 = 7
2 x 7 = 14
3 x 7 = 21
4 x 7 = 28
5 x 7 = 35
6 x 7 = 42
7 x 7 = 49
8 x 7 = 56
9 x 7 = 63
10 x 7 = 70
11 x 7 = 77
12 x 7 = 84
```


<span id="Fibonacci"><br><br></span>

# <span><a href="#Pythagoras">[&nabla;]</a></span> <span><a href="#Multiple">[&Delta;]</a></span> <span><a href="#Plan">[@]</a> </span> <span style="color: red;">Suite de Fibonacci</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   Rafael Ortiz
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-09-29 Jean.Thiery@ModLibre.info
#
# Title:          Fibonacci Series
# Author:         Rafael Ortiz
# About:          The Fibonacci Number Series
# Shows:          Using tuple assignments. While loop
# XOversion:  --> Bundled in 656 ?

a, b = 0, 1
while b < 1001:
    print (b, end=" ")	
    a, b = b, a+b

# Initial version in Python 2 ##########################################
# Title:          Fibonacci Series
# Author:         Rafael Ortiz
# About:          The Fibonacci Number Series
# Shows:          Using tuple assignments. While loop.
# XOversion:      Bundled in 656
#
#   a, b = 0, 1
#   while b < 1001:
#       print b,
#       a, b = b, a+b```
```
```
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
```


<span id="Pythagoras"><br><br></span>

# <span><a href="#Pascal">[&nabla;]</a></span> <span><a href="#Fibonacci">[&Delta;]</a></span> <span><a href="#Plan">[@]</a></span> <span style="color: red;">Pythagore</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   Rafael Ortiz
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-09-29 Jean.Thiery@ModLibre.info
#
# Title:          Pythagoras
# Author:         Rafael Ortiz
# About:          Uses Pythagorean Theorem to compute longest edge of a triangle
# Shows:          Import statement, sqrt (square root) function.

import math
from math import sqrt

print("This is the Pythagoras Theorem")
a = float(input("Type a = "))
b = float(input("Type b = "))

c = sqrt((a*a)+(b*b))

print("c = ",c)

# Initial version in Python 2 ##########################################
# Title:          Pythagoras
# Author:         Rafael Ortiz
# About:          Uses Pythagorean Theorem to compute longest edge of a triangle
# Shows:          Import statement, sqrt (square root) function.
#
#   import math
#   from math import sqrt
#
#   print "This is the Pythagoras Theorem"
#   a=float(raw_input("Type a ="))
#   b=float(raw_input("Type b ="))
#
#   c=sqrt((a*a)+(b*b))
#
#   print "c =",c
```
```
This is the Pythagoras Theorem
Type a = 3
Type b = 4
c =  5.0
```


<span id="Pascal"><br><br></span>

# <span><a href="#Sierpinsky">[&nabla;]</a></span> <span><a href="#Pythagoras">[&Delta;]</a></span> <span><a href="#Plan">[@]</a> </span> <span style="color: red;">Triangle de Pascal</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   Madeleine Ball
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-09-29 Jean.Thiery@ModLibre.info
#
# Title:          Pascal's triangle
# Author:         Madeleine Ball
# About:          Character graphic of Pascal's triangle
# Shows:          loops, vectors
# XOversion:  --> Bundled in 656 ?

# Pascal's triangle

lines = 8
vector = [1]

for i in range(0,lines):
  vector.insert(0,0)
  vector.append(0)

for i in range(0,lines):
  newvector = vector[:]
  for j in range(0,len(vector)-1):
    if newvector[j] == 0:
      print ("  ", end=""),
    else:
      print ("%2d" % newvector[j], end="")
    newvector[j] = vector[j-1] + vector[j+1]
  print(" ")
  vector = newvector[:]

# Initial version in Python 2 ##########################################
# Title:          Pascal's triangle
# Author:         Madeleine Ball
# About:          Character graphic of Pascal's triangle
# Shows:          loops, vectors
# XOversion:      Bundled in 656
#
#   lines = 8
#   vector = [1]
#
#   for i in range(0,lines):
#     vector.insert(0,0)
#     vector.append(0)
#
#   for i in range(0,lines):
#     newvector = vector[:]
#     for j in range(0,len(vector)-1):
#       if newvector[j] == 0:
#         print "  ",
#       else:
#         print "%2d" % newvector[j],
#       newvector[j] = vector[j-1] + vector[j+1]
#     print
#     vector = newvector[:]
```
```
                 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 
```


<span id="Sierpinsky"><br><br></span>

# <span><a href="#Guess">[&nabla;]</a></span> <span><a href="#Pascal">[&Delta;]</a></span> <span><a href="#Plan">[@]</a></span> <span style="color: red;">Triangle de Sierpinsky</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   Madeleine Ball
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-09-29 Jean.Thiery@ModLibre.info
#
# Title:          Sierpinsky triangle
# Author:         Madeleine Ball
# About:          Character graphics of a Sierpinski triangle
# Shows:          Modifying Pascal's triangle program, loops, vectors
# XOversion:  --> Bundled in 656 ?

size = 5
modulus = 2

lines = modulus**size

vector = [1]
for i in range(0,lines):
  vector.insert(0,0)
  vector.append(0)

for i in range(0,lines):
  newvector = vector[:]
  for j in range(0,len(vector)-1):
    if newvector[j] == 0:
      print(" ", end="")
    else:
      remainder = newvector[j] % modulus
      if remainder == 0:
        print("O", end="")
      else:
        print(".", end="")
    newvector[j] = vector[j-1] + vector[j+1]
  print(" ")
  vector = newvector[:]

# Initial version in Python 2 ##########################################
# Title:          Sierpinski triangle
# Author:         Madeleine Ball
# About:          Character graphics of a Sierpinski triangle
# Shows:          Modifying Pascal's triangle program, loops, vectors
# XOversion:      Bundled in 656
#
#   size = 5
#   modulus = 2
#
#   lines = modulus**size
#
#   vector = [1]
#   for i in range(0,lines):
#     vector.insert(0,0)
#     vector.append(0)
#
#   for i in range(0,lines):
#     newvector = vector[:]
#     for j in range(0,len(vector)-1):
#       if newvector[j] == 0:
#     print " ",
#     else:
#       remainder = newvector[j] % modulus
#       if remainder == 0:
#         print "O",
#       else:
#         print ".",
#     newvector[j] = vector[j-1] + vector[j+1]
#   print
#   vector = newvector[:]
```
```
                                .                                
                               . .                               
                              . O .                              
                             . . . .                             
                            . O O O .                            
                           . . O O . .                           
                          . O . O . O .                          
                         . . . . . . . .                         
                        . O O O O O O O .                        
                       . . O O O O O O . .                       
                      . O . O O O O O . O .                      
                     . . . . O O O O . . . .                     
                    . O O O . O O O . O O O .                    
                   . . O O . . O O . . O O . .                   
                  . O . O . O . O . O . O . O .                  
                 . . . . . . . . . . . . . . . .                 
                . O O O O O O O O O O O O O O O .                
               . . O O O O O O O O O O O O O O . .               
              . O . O O O O O O O O O O O O O . O .              
             . . . . O O O O O O O O O O O O . . . .             
            . O O O . O O O O O O O O O O O . O O O .            
           . . O O . . O O O O O O O O O O . . O O . .           
          . O . O . O . O O O O O O O O O . O . O . O .          
         . . . . . . . . O O O O O O O O . . . . . . . .         
        . O O O O O O O . O O O O O O O . O O O O O O O .        
       . . O O O O O O . . O O O O O O . . O O O O O O . .       
      . O . O O O O O . O . O O O O O . O . O O O O O . O .      
     . . . . O O O O . . . . O O O O . . . . O O O O . . . .     
    . O O O . O O O . O O O . O O O . O O O . O O O . O O O .    
   . . O O . . O O . . O O . . O O . . O O . . O O . . O O . .   
  . O . O . O . O . O . O . O . O . O . O . O . O . O . O . O .  
 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
```


<span id="Guess"><br><br></span>

# <span><a href="#Gym">[&nabla;]</a></span> <span><a href="#Sierpinsky">[&Delta;]</a></span> <span><a href="#Plan">[@]</a></span> <span style="color: red;">Devine un nombre</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   Pilar Saenz
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-09-29 Jean.Thiery@ModLibre.info
#
# Title:          Guess a number
# Author:         Pilar Saenz
# About:          Numerical tests
# Shows:          Tests, While loop
# XOversion:  --> Bundled in 656 ?

import random
from random import randrange
R = randrange(1,100)

print(            "Guess a number between  1 and 100 !!!")
print(            "Trouver un nombre entre 1 et  100 !!!")
N = int(input(    "Enter a number        | Entrez un nombre : "))
i=1
while N!=R:
    if N>R :
        print(    "Too big...  try again | Trop grand... Essayez de nouveau")
    else :
        print(    "Too small.. try again | Trop petit... Essayez de nouveau")
    N = int(input("Enter a number        | Entrez un nombre : "))	
    i+=1
print("You got it in         ", i, "tries")
print("Vous l'avez obtenu en ", i, "essais")

# Initial version in Python 2 ##########################################
# Title:           Guess a number
# Author:          Pilar Saenz
# About:           Numerical tests
# Shows:           Tests, While loop
# XOversion:       Bundled in 656

#   import random
#   from random import randrange
#   R = randrange(1,100)
#
#   print "Guess a number between 1 and 100!!!"
#   N = int(raw_input("Enter a number: "))
#   i=1
#   while N!=R:
#       if N>R :
#           print "Too big... try again"
#       else :
#           print "Too small.. try again"
#       N = input("Enter a number: ")
#       i+=1
#   print "You got it in ", i, "tries"
```
```
Guess a number between  1 and 100 !!!
Trouver un nombre entre 1 et  100 !!!
Enter a number        | Entrez un nombre : 50
Too small.. try again | Trop petit... Essayez de nouveau
Enter a number        | Entrez un nombre : 75
Too small.. try again | Trop petit... Essayez de nouveau
Enter a number        | Entrez un nombre : 87
Too big...  try again | Trop grand... Essayez de nouveau
Enter a number        | Entrez un nombre : 81
Too big...  try again | Trop grand... Essayez de nouveau
Enter a number        | Entrez un nombre : 78
Too small.. try again | Trop petit... Essayez de nouveau
Enter a number        | Entrez un nombre : 79
You got it in           6 tries
Vous l'avez obtenu en   6 essais
```


<span id="Gym"><br><br></span>

# <span><a href="#Final">[&nabla;]</a></span> <span><a href="#Guess">[&Delta;]</a></span> <span><a href="#Plan">[@]</a></span> <span style="color: red;">Gymnastique</span>

```{Python}
# Copyright (C)   2007-2022  Creative Commons Attribution 2.5
#                            https://wiki.laptop.org/go/Pippy
# Initial version Python 2   C. Scott Ananian
# Translated into Python 3   Jean.Thiery@ModLibre.info
# Version         2022-10-01 Jean.Thiery@ModLibre.info
#
# Title:          jumping man
# Author:         C. Scott Ananian
# About:          Display
# Shows:          Print Statements
# XOversion:  --> Bundled in 656 ?

# both of these functions should be in the 'basic' package or some such
def clear_scr():
    print ('\x1B[H\x1B[J') # clear screen, the hard way.

def wait():
    import time
    time.sleep(0.1)
    
# jumping man!
# was having to escape the backslash which was rather unfortunate, 
# now using python's r" strings which were meant for regex's
# i didn't have to do that in C64 BASIC
for i in range(50):
    clear_scr()
    print ("\o/")
    print ("_|_")
    print ("   ")
    wait()

    clear_scr()
    print ("_o_")
    print (" | ")
    print ("/ \ ")
    wait()

    clear_scr()
    print (" o ")
    print ("/|\ ")
    print ("| |")
    wait()

    clear_scr()
    print ("_o_")
    print (" | ")
    print ("/ \ ")
    wait()

# Initial version in Python 2 ##########################################
# Title:          jumping man
# Author:         C. Scott Ananian
# About:          Display
# Shows:          Print Statements
# XOversion:      Bundled in 656
#
# both of these functions should be in the 'basic' package or some such
#   def clear_scr():
#       print '\x1B[H\x1B[J' # clear screen, the hard way.
#   def wait():
#       import time
#       time.sleep(0.1)
#
# jumping man!
# was having to escape the backslash which was rather unfortunate, 
# now using python's r" strings which were meant for regex's
# i didn't have to do that in C64 BASIC
#   for i in xrange(50):
#   for i in xrange(50):
#       clear_scr()
#       print r"\o/"
#       print r"_|_"
#       print r"   "
#       wait()
#
#       clear_scr()
#       print r"_o_"
#       print r" | "
#       print r"/ \ "
#       wait()
#
#       clear_scr()
#       print r" o "
#       print r"/|\ "
#       print r"| |"
#       wait()
#    
#       clear_scr()
#       print r"_o_"
#       print r" | "
#       print r"/ \ "
#       wait()
```
```
\o/      _o_       o       _o_      \o/      _o_       o       _o_
_|_       |       /|\       |       _|_       |       /|\       |    
         / \      | |      / \               / \      | |      / \   ...
```


<span id="Final"><br><br></span>

# <span><a href="#Initial">[@]</a></span> <span><a href="#Gym">[&Delta;]</a></span> <span style="color: red;">Fin</span>

***
##### [2022-10-25 &nbsp;&nbsp;&nbsp; © 2022-2022 ModLibre.info](http://ModLibre.info) &nbsp;&nbsp;&nbsp; [licence cc-by-sa](http://creativecommons.org) &nbsp;&nbsp;&nbsp; [Source](Python_OLPC.Rmd) &nbsp;&nbsp;&nbsp; [W3C](http://validator.w3.org/) &nbsp;&nbsp;&nbsp; [HTML5](https://fr.wikipedia.org/wiki/HTML5) &nbsp;&nbsp;&nbsp; [CSS](http://jigsaw.w3.org/css-validator/)
***

