Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:11:06+00:00 2026-06-02T07:11:06+00:00

I have a homework assignment for a Python class and am running into an

  • 0

I have a homework assignment for a Python class and am running into an error that I don’t understand. Running Python IDLE v3.2.2 on Windows 7.

Below is where the problem is happening:

#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

This is the error that I am getting:

Traceback (most recent call last): File “I:\Cent 110\test.py”, line 19, in openfile.write(item+’\n’)
AttributeError: ‘tuple’ object has no attribute ‘write’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:11:07+00:00Added an answer on June 2, 2026 at 7:11 am

    You’re missing the open.

    openfile = open('test.txt','w')
    

    And at the end there are missing parens when you try to close the file

    openfile.close()
    

    Edit: I just saw another problem.

    openfile.write(str(cost)+'\n')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a homework question that says: Problem 1: Given the array [ 22
I have done a homework assignment, here is the problem statement: Your program should
For my homework assignment, I have a network of Nodes that are passing messages
I have a homework assignment in Java that is tested using the commands: make
I have a homework assignment where I am buildign a GUI JPane that holds
I have a homework assignment that I am supposed to write a http server
I have some code below. This code is a basic push/pop stack class that
Im almost done with a homework assignment that multiplies polynomials and has to have
For a homework assignment I was given a Card class that has enumerated types
In Python, I have a Graph class that has a dictionary of vertex objects.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.