У меня есть домашнее задание для класса Python, и я столкнулся с ошибкой, которую не понимаю. Запуск Python IDLE v3.2.2 в Windows 7.
Ниже показано, где возникает проблема:
#local variables
number=0
item=''
cost=''
#prompt user how many entries
number=int(input('\nHow many items to add?: '))
#open file
openfile=('test.txt','w')
#starts for loop to write new lines
for count in range(1,number+1):
print('\nFor item #',count,'.',sep='')
item=input('Name: ')
cost=float(input('Cost: $'))
#write to file
openfile.write(item+'\n')
openfile.write(cost+'\n')
#Display message and closes file
print('Records written to test.txt.',sep='')
openfile.close
Это ошибка, которую я получаю:
Traceback (последний последний вызов): File "I:\Cent 110\test.py", строка 19, в openfile.write(item+'\n')
AttributeError: объект «кортеж» не имеет атрибута «запись»