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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:38:39+00:00 2026-05-22T15:38:39+00:00

I know this is a very simple question, but unfortunately I don’t know enough

  • 0

I know this is a very simple question, but unfortunately I don’t know enough to search effectively for an answer. Any answers or links to things I should already know would be greatly appreciated.

What I am trying to do is make an environment in Python where I have a bunch of turtles running around doing various things (it’s basically like StarLogo from MIT).

class Turtle:
    def __init__(self,x,y):
        self.xpos = float(x)
        self.ypos = float(y)
        self.head = 0.0

numTurtles = 4
for i in range(numTurtles):
    ...
MyTurtles = [...]

Each turtle has an x position, a y position, and a heading (in radians). All I want to do is create them and tell them where to stand (their x and y coordinates), and then put all the turtles into a list so that later I can tell the whole group to take a certain action.

I want to be able to change the number of turtles, otherwise I would just call them [a,b,c,d]. But I figure there has to be a better way.

  • 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-22T15:38:40+00:00Added an answer on May 22, 2026 at 3:38 pm

    You should add the turtles to the list directly while executing the loop, for example

    my_turtles = []
    for i in range(num_turtles):
        x = ...
        y = ...
        h = ...
        my_turtles.append(Turtle(x, y, h))
    

    It’s often also possible to write this as a “list comprehension”:

    my_turtles = [Turtle(..., ..., ...) for i in range(num_turtles)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a darn simple question, but I'm very used to using
I know this is probably a very simple question, but I can't seem to
This should be a fairly simple question but I know very little about SQL.
I realize this may be a very simple question but I need to know
Warning - I am very new to NHibernate. I know this question seems simple
I know this maybe a very basic question but I'm having a bit of
I think this is a very simple question, but when I copy an image
Ok, this is a very simple question. I am actually 90% sure I know
This may seem like a very simple question, but I have been struggling with
My problem is very simple, but I really don't know how to manipulate strings

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.