So I am trying to make a piggybank in Python that uses file IO by opening a file that I already made and replacing the current text with new text. Then it will save the file and that is how it saves the money. But, it is not working and tells me that there is an error. Can somebody help?
def piggybank():
file = open('piggybank.txt','wb')
addedmoney = input('How much money are you adding?')
previousamount = file.read()
newamount = addedmoney + previousamount
for line in file:
line.replace(newamount)
print("You now have:\n", newamount)