incrémentation dans la liste
Bonjour ,
je suis débutant en python
voici mon code , j'arrive pas incrémenter dans Tliste = [] afin de créer la somme de Tliste
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
def acheter(self):
encoreproduit = True
while (encoreproduit):
id = input("veuillez saisir un id : ")
if (id == ""):
encoreproduit = False
break;
id = int(id)
f = open(facture.nomproduit, "r")
liste = f.readlines()
f.close()
Tliste = []
for i in range(1, len(liste)):
listechamps = liste[i].split(" ")
while(int(listechamps[0]) == id):
f1 = open(self.nomfacture, "a")
liignefacture = "\n" + " ".join(listechamps[0:3]) + "\n"
Tliste.append(listechamps[2])
print("produit : ", liignefacture)
f1.write(liignefacture)
f1.close()
newstock = int(listechamps[-1]) - 1
listechamps[-1] = str(newstock)
nouvelleligne = " ".join(listechamps) + "\n"
liste[i] = nouvelleligne
break
print(Tliste)
f = open(facture.nomproduit, "w")
for element in liste:
f.write(element)
f.close() |
et Merci