def afficher_allumettes(N):
    
    print(f"Il y a {N} allumettes sur la table:")
    print("   " + "|" * N)
    
def choisir_nombre():
    
    choix = input("Combien veux-tu prendre d'allumettes ?")
    
    if choix != "1" and choix != "2" and choix != "3":
        print("Tu ne peux choisir que 1, 2 ou 3 allumettes!")
        return choisir_nombre()
    else:
        return int(choix)
    
def partie_allumettes(N):
    
    n_restant = N
    joueur = 1
    
    while n_restant > 1:
        afficher_allumettes(n_restant)
        print(f"C'est le tour du joueur {joueur}")
        choix = choisir_nombre()
        n_restant -= choix
        joueur = 2 if joueur == 1 else 1
        
    print(f"Le joueur {joueur} a perdu !")

partie_allumettes(30)
