I have a homework for the Python class, and I am facing an error that I do not understand. Running Python IDLE v3.2.2 on Windows 7.
The following is the problem:
number=0
item=''
cost=''
number=int(input('\nHow many items to add?: '))
openfile=('test.txt','w')
for count in range(1,number+1):
print('\nFor item #',count,'.',sep='')
item=input('Name: ')
cost=float(input('Cost: $'))
openfile.write(item+'\n')
openfile.write(cost+'\n')
print('Records written to test.txt.',sep='')
openfile.close
This is the error I get:
Traceback (last last call): File "I: \ Cent 110 \ test.py", line 19, in openfile.write (item + '\ n')
AttributeError: object 'tuple' does not have attribute 'write'
source
share