From d7221b71ffdc56ec0e5f03a9578ed21c907064bd Mon Sep 17 00:00:00 2001 From: ROBINET Julien Date: Fri, 27 Mar 2026 14:14:29 +0100 Subject: [PATCH] obtimisation fonction spawn_rectangle --- projet_tkinter_sujet5.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/projet_tkinter_sujet5.py b/projet_tkinter_sujet5.py index 6d7c334..45d5a0e 100644 --- a/projet_tkinter_sujet5.py +++ b/projet_tkinter_sujet5.py @@ -2,18 +2,9 @@ import tkinter as tk from random import randint def spawn_rectangle() : - indice_couleur = randint(0, 4) - couleur = 0 - if indice_couleur == 0 : - couleur = "red" - if indice_couleur == 1 : - couleur = "green" - if indice_couleur == 2 : - couleur = "blue" - if indice_couleur == 3 : - couleur = "yellow" - if indice_couleur == 4 : - couleur = "grey" + lst = ["red", "blue", "green", "yellow", "grey"] + indice_couleur = randint(0, len(lst)-1) + couleur = lst[indice_couleur] taille = randint(10, 30) position_x = randint(0, 400) position_y = randint(0, 300)