i trying make bank , failing change integer data of file. file contains is:
astle,hello,11 monish,mr7,0
now in 'choice1'(later show in code) when try deposit suppose 100 , not change value instead gives same value.like in case if enter username 'astle' , try deposit 100 , value becomes 100 , not 111.i want 111 when deposit should old value + newvalue.
have tried following code of no avail.
this code:
import csv run=true while run==true: print "1) deposit money" choice=input("enter choice on here: ") #this part takes input user , stores in 'store.txt' if choice==1: b=raw_input("enter username: " ) open('store.txt','r') f: reader = list(csv.reader(f)) row in reader: if b==row[0]: #check username file c=input("enter new ammount") print row[2],"old value" a=int(row[2]) print row[2] = c print row[2],"new value" flag = 1 break else: flag=0 if flag==0: print "username not exist." #writes new value in file open('store.txt','w') f: wr = csv.writer(f) row in reader: wr.writerow(row)
i have tried replacing row[2] = c row[2] += c gives me following error:
row[2]+=d typeerror: cannot concatenate 'str' , 'int' objects
you need convert value str
int
. try this.
row[2] = str(int(row[2]) + c)