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

  • SEARCH
  • Home
  • 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 6174843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:49:13+00:00 2026-05-23T23:49:13+00:00

I am trying to write a program where my brother and I can enter

  • 0

I am trying to write a program where my brother and I can enter and edit information from our football game rosters to compare teams and manage players, etc.
This is my first ‘big’ project i’ve tried.

I have a nested dictionary inside a dictionary, I’m able to get the user to create the dictionaries etc. But when i try to have the ‘user’ (via raw_input) go back to edit them I get stuck.
Below i tried to put a simplified version of the code down of what i think is relevant to my error. If I need to put down a full version let me know.

player1 = {'stat1' : A, 'stat2' : 2, 'stat3' : 3} #existing players are the dictionaries 
player2 = {'stat1' : A, 'stat2' : 2, 'stat3' : 3} # containing the name of stat and its value
position1 = {'player1' : player1} # in each position the string (name of player) is the key and
position2 = {'player2' : player2} # the similarly named dict containing the statisics is the value
position = raw_input('which position? ') # user chooses which position to edit
if position == 'position1':
  print position1 # shows user what players are available to choose from in that position
  player = raw_input('which player? ') #user chooses player from available at that position
  if player == player1:
    print player # shows user the current stats for the player they chose
    edit_query = raw_input('Do you need to edit one or more of these stats? ')
    editloop = 0
    while editloop < 1: # while loop to allow multiple stats editing
      if edit_query == 'yes': 
        stat_to_edit = raw_input('Which stat? (If you are done type "done") ')
          if stat_to_edit == 'done': #end while loop for stat editing
            editloop = editloop +1
          else:
            new_value = raw_input('new_value: ') #user inserts new value

# up to here everything is working. 
# in the following line, player should give the name of the
# dictionary to change (either player1 or player2) 
# stat_to_edit should give the key where the matching value is to be changed
# and new_value should update the stastic
# however I get TypeError 'str' object does not support item assignment

            player[stat_to_edit] = new_value #update statistic
      else:  # end loop if no stat editing is wanted
        fooedit = fooedit + 1

of course when i say “should give…” etc I mean to say “I want it to give..”

In summary I want the user to choose the player to edit, choose the stat to edit, then choose the new value

  • 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-05-23T23:49:14+00:00Added an answer on May 23, 2026 at 11:49 pm

    The problems seems that after this line

    player = raw_input('which player? ')
    

    the player will be the string, containing what the user have typed in, and not the dictionary, like player1. This explains, why Python fails to assign to its part. You can instead write like this:

    player = raw_input('which player? ')
    if player == 'player1': # these are strings!
      current_player = player1 # this is dictionary!
      ....
      current_player[...] = ... # change the dictionary
    

    Also note, that the Python assignment to a name typically does no copy object, but only adds another name for the same existing object. Consider this example (from Python console):

    >>> a = {'1': 1}
    >>> a
    {'1': 1}
    >>> b = a
    >>> b
    {'1': 1}
    >>> b['1'] = 2
    >>> b
    {'1': 2}
    >>> a
    {'1': 2}
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program that reads text from external file (string string
I'm trying to write a program that can password protect individual folders, but I'm
I'm trying to write a program that outputs data that can be served over
I'm trying to write a program that reads 2 numbers from the user and
I'm trying to write a program that prints all numbers from 0 to 1,000
I am trying to write a program using python-fuse, but I can't get file
I'm trying to write a program that reads 2 numbers from the user and
I am trying to write a program to simulate a card game. I have
I'm trying to write a program to calculate triangles. Can anyone give me a
I am trying to write a program that can replace text and replace also

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.