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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:15:43+00:00 2026-06-03T20:15:43+00:00

I am new to programming and i am just going through a python book.

  • 0

I am new to programming and i am just going through a python book. I want to have multiple robots to run inside a map. There will be multiple Robot(s) in a Map. what do i need to do to the map class to have it work this way? I know this is vague but i am 14 and trying hard to explain this.

class Map:

    def __init__(self):
        self.robot = []

    def add_robot(self, robot):
        self.robot.add(Robot)

    def is_occupied(self, x, y):
        for r in self.robot:
            if r.xpos == x and r.ypos == y:
                return True
        return False


class Robot(Map):

    def __init__(self):
        self.xpos = 0
        self.ypos = 0

    def step(self, axis):
        if axis in "xX":
            if self.is_occupied(self.xpos+1, self.ypos):
                self.xpos += 1 
                print "step X axis"
        elif axis in "yY":
            self.ypos += 1

    def walk(self, axis, steps=2):
        for i in range(steps):
            self.step(axis)

    def get_pos(self):
        print "X:%i  Y:%i" % (self.xpos, self.ypos)


robot1 = Robot()
robot1.walk("x", 5)
robot1.get_pos()

If i do not have the ‘Map’ class this works just fine but i cannot get map class to work. I got help making the map class but i cant get it to work with my Robot class.

  • 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-03T20:15:45+00:00Added an answer on June 3, 2026 at 8:15 pm

    You have Robot as a subclass of Map; this is not how inheritance should be used. Think “subclass” rather than “child class.”

    Consider this:

    class Animal:
    
        def eat(self, food):
            print "mmm"
    
    
    class Human(Animal):
    
        def speak(self, words):
            print words
    

    A human IS A animal; it can speak, but it can eat.

    A robot is obviously not a map. I believe you are thinking of a map having robots, and it should work if you make Robot not a subclass. Oh, and change self.robot to self.robots.

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

Sidebar

Related Questions

I'm new to programming and currently going through the exercises in Zed Shaw's Python
I was going through the Programming Interviews Exposed book. There's a code given for
I am just new to programming in Unix and have a small issue that
I'm a designer and brand new to programming. I have just opened my localhost
I'm fairly new the functional programming, so I'm going through some practice exercises. I
I am very new to programming. I want to be able to run this
I'm new to C programming and I just came across this program and got
I am new to programming but had some spare time and just got a
i'm just new to iOS Programming, so appreciate for any help. I'm trying to
I'm new to silverlight and wpf programming I've just created a simple storyboard in

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.