This is my first question on Stack. I hope the explanation is understandable, and the posts' rules respected.
Problem : I try to create a display of 12 multiplication tables, 5 by 5. The code runs well, but it never stops. It seems to be a problem in the syntax of the while loop.
What I tried :
- changing the while condition with :
while lot_tab != [0]: # Stop quand vide.
while lot_tab != [""]: # Stop quand vide.
Nothing works, I don't understand. So I'm asking for your help.
Code :
LIGNE_TMUL = "%2i x %2i = %3i "
nmax = 12
tab_par_lig = 5
tab_total = range(1, nmax + 1) # Soit ici 12.
lot_tab = tab_total[:tab_par_lig] # Prends un lot de 5 pour l'affichage.
tab_total = tab_total[tab_par_lig:] # Les enleve du stock restant.
# while tab_total != []: # Test
while lot_tab != []: # Stop quand vide.
for x in range(1, nmax + 1): # traîter les nombres de 1 à 12.
accumul = [] # Stock 1 ligne d'une table.
for y in lot_tab: # Construit les colonnes.
accumul.append(LIGNE_TMUL%(y, x, x * y)) # Stock une ligne dans accumul[]
print("".join(accumul)) # Affiche la ligne créée avec y
print("\n") # Separation verticale entre blocs de tables.
lot_tab = tab_total[:tab_par_lig] # Prends un lot de 5 pour l'affichage.
tab_total = tab_total[tab_par_lig:]