Question
This is the question: You are given the following two classes. ### Do not change the Location or Campus classes. ### ### Location class is
This is the question:
You are given the following two classes.
### Do not change the Location or Campus classes. ### ### Location class is the same as in lecture. ### class Location(object): def __init__(self, x, y): self.x = x self.y = y def move(self, deltaX, deltaY): return Location(self.x + deltaX, self.y + deltaY) def getX(self): return self.x def getY(self): return self.y def dist_from(self, other): xDist = self.x - other.x yDist = self.y - other.y return (xDist**2 + yDist**2)**0.5 def __eq__(self, other): return (self.x == other.x and self.y == other.y) def __str__(self): return '<' + str(self.x) + ',' + str(self.y) + '>' class Campus(object): def __init__(self, center_loc): self.center_loc = center_loc def __str__(self): return str(self.center_loc)
Implement a class that meets the specifications below.
class MITCampus(Campus): """ A MITCampus is a Campus that contains tents """ def __init__(self, center_loc, tent_loc = Location(0,0)): """ Assumes center_loc and tent_loc are Location objects Initializes a new Campus centered at location center_loc with a tent at location tent_loc """ # Your code here def add_tent(self, new_tent_loc): """ Assumes new_tent_loc is a Location Adds new_tent_loc to the campus only if the tent is at least 0.5 distance away from all other tents already there. Campus is unchanged otherwise. Returns True if it could add the tent, False otherwise. """ # Your code here def remove_tent(self, tent_loc): """ Assumes tent_loc is a Location Removes tent_loc from the campus. Raises a ValueError if there is not a tent at tent_loc. Does not return anything """ # Your code here def get_tents(self): """ Returns a list of all tents on the campus. The list should contain the string representation of the Location of a tent. The list should be sorted by the x coordinate of the location. """ # Your code here
For example, if c = MITCampus(Location(1,2)) then executing the following sequence of commands:
c.add_tent(Location(2,3)) should return True c.add_tent(Location(1,2)) should return True c.add_tent(Location(0,0)) should return False c.add_tent(Location(2,3)) should return False c.get_tents() should return ['<0,0>', '<1,2>', '<2,3>']
Paste your entire class MITCampus in the box below. Do not leave any debugging print statements.
This is my answer but it get error
# Paste your class here def __init__(self,x,y): self.x = x self.y = y def move(self, deltaX, deltaY): return Location(self.x + deltaX, self.y + deltaY) def getX(self): return self.x def getY(self): return self.y def dist_from(self, other): xDist = self.x - other.x yDist = self.y - other.y return (xDist**2 + yDist**2)**0.5 def __eq__(self, other): return (self.x == other.x and self.y == other.y) def __str__(self): return '<' + str(self.x) + ',' + str(self.y) + '>' class Campus(object): def __init__(self,center_loc): self.center_loc = center_loc def __str__(self): return str(self.center_loc) class MITCampus(Campus): def __init__(self, center_loc, tent_loc = (Location(0,0))): Campus.__init__(self,center_loc) self.tents = [] self.tents.append(tent_loc) def add_tent(self, new_tent_loc): for loc in self.tents: if(new_tent_loc.dist_from(loc)<0.5): return False self.tents.append(new_tent_loc) return True def remove_tent(self, tent_loc): for loc in self.tents: if(loc.__eq__(tent_loc)): self.tents.remove(tent_loc) return raise ValueError('could not find lacation '+ tent_loc.__str__()) def get_tents(self): self.tents.sort(key=lambda loc: loc.x) ans = "['" for loc in self.tents: ans += loc.__str__()+"','" ans = ans.rstrip(",'") ans += "']"
the error messege is
File "submission.py", line 48 def __init__(self,center_loc): ^ IndentationError: expected an indented block
can you please help me with the indent too thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started