I have this code and i cant fix it. Its a small program, just started learning. How do i add multiple values from the same variable to a txt file in python It will add the same value to the txt, if you enter two different values, it will still put the first one two times.
broj = int(input('Unesite broj puta koliko zelite da ponovite: '))
listaCena = []
if broj>0:
for i in range(broj):
amount = int(input('Unesite cenu: '))
pdv_amount = int(input('Unesite pdv: '))
pdv = (amount/100)* pdv_amount + amount
initial = mn(amount, pdv)
listaCena.append(initial)
for cena in listaCena:
print("-"*50)
print('{} {} | {} {}'.format('Ukupno: ', cena['amount'],
'Sa PDV-om: ', cena['pdv']))
text_file = open("cene.txt", "a")
for i in range(broj):
text_file.write('{} {} | {} {}'.format('Ukupno: ', cena['amount'],
'Sa PDV-om: ', cena['pdv'])+'\n')
text_file.close()
Comments
Post a Comment