I’m learning Python-this gives me an IO error-
f = open('money.txt')
while True:
currentmoney = float(f.readline())
print(currentmoney, end='')
if currentmoney >= 0:
howmuch = (float(input('How much did you put in or take out?:')))
now = currentmoney + howmuch
print(now)
str(now)
f.close()
f = open('money.txt', 'w')
f.write(str(now))
f.close()
Thanks!
The
while Trueis going to loop forever unless you break it withbreak.The I/O error is probably because when you have run through the loop once the last thing you do is
f.close(), which closes the file. When execution continues with the loop in the linecurrentmoney = float(f.readline()):fwill be a closed filehandle that you can’t read from.