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 8483787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:12:08+00:00 2026-06-10T20:12:08+00:00

Having a problem with a code for homework. Basically what I’m trying to do

  • 0

Having a problem with a code for homework. Basically what I’m trying to do is take in a list of objects and pass them to my fire method.

def fire(self,targets):
    i = 0
    for i in targets:
        x,y = targets[i].position
        tx,ty = self.position
        d = getDist(targets[i].position, self.position)

Whenever I call the fire method and pass in the objects it points me to line 17 which is the x,y = targets[i].position line and says “TypeError: list indices must be integers, not Bomber”

Bomber is the name of the class. I call the fire method like this:

bOne.fire([bTwo, tOne, tTwo, tThree])

Any help is much appreciated.

  • 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-10T20:12:09+00:00Added an answer on June 10, 2026 at 8:12 pm

    You are looping over the list itself, which means you don’t need to use the values as an index:

    >>> for elem in ['a', 'b', 'c']:
    ...     print elem
    'a'
    'b'
    'c'
    

    In python, the for construct doesn’t work just with numbers, it works directly with the elements of the sequence you are looping over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically i am having problems with my code - this is homework so would
I am having a problem getting this code to work. Basically I Go from
I am having a problem in this code. what i am trying to do
I am having problem with my jquery code, I am trying to state that
I'm having a problem with some code in Visual C++ 2010 Express. I'm trying
hi i'm having a problem with this code. my problem is that the first
I'm having a problem with this code: #include <iostream> using namespace std; class A
I'm having a problem with some code I've written. I've had to anonymize it,
I'm having a problem with some code that used to work in PHP 4.X
I am having problem getting this piece of code to run. The class is

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.