Skip to content

Instantly share code, notes, and snippets.

@vbarthel-fr
Created May 4, 2019 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbarthel-fr/eff73ee261c9c85abf251a4049363018 to your computer and use it in GitHub Desktop.
Save vbarthel-fr/eff73ee261c9c85abf251a4049363018 to your computer and use it in GitHub Desktop.
Tenuun: random images

Sortie possible 1

L'image orange sera en position 5
Voici la liste des images. Rappel: la premiere case d'une liste a l'index 0.
L'index 5 correspond donc a la case 6
['red_image', 'red_image', 'red_image', 'red_image', 'red_image', 'orange_image', 'red_image', 'red_image', 'red_image']

Sortie possible 2

L'image orange sera en position 1
Voici la liste des images. Rappel: la premiere case d'une liste a l'index 0.
L'index 1 correspond donc a la case 2
['red_image', 'orange_image', 'red_image', 'red_image', 'red_image', 'red_image', 'red_image', 'red_image', 'red_image']
import random
# Ici je retourne simplement un chaine de caractere
# Il faudrait recuperer l'image orange
def get_orange_image():
return "orange_image"
# Pareil pour l'image rouge
def get_red_image():
return "red_image"
# Nombre total d'images
nb_images = 9
# Index de l'image orange choisi aleatoirement entre 0 et nb_image.
# random.randint(0, 10) -> genere un nombre aleatoire entre 0 et 10.
# Dans notre liste, les index commence a 0, d'ou le "- 1":
# Il y a bien 9 combinaisons possibles entre 0 et 8:
# 0, 1, 2, 3, 4, 5, 6, 7, 8
index_image_orange = random.randint(0, nb_images - 1)
print "L'image orange sera en position " + str(index_image_orange)
# Liste qui va contenir toutes mes images
images = []
# On va boucler avec un index entre 0 et nb_images
# "index" va avoir la valeur 0, puis 1, puis 2, puis 3, etc.
for index in range(0, nb_images):
if index == index_image_orange:
# C'est notre image orange !
new_image = get_orange_image()
images.append(new_image)
else:
# C'est une image rouge !
new_image = get_red_image()
images.append(new_image)
# On a ici une liste de nb_images avec une image orange
print "Voici la liste des images. Rappel: la premiere case d'une liste a l'index 0."
print "L'index " + str(index_image_orange) + " correspond donc a la case " + str(index_image_orange + 1)
print images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment