On Saturday, July 29, 2017 at 2:16:36 PM UTC-5, new_to_c0ding wrote: > Hello all, I have been scratching my head since morning but > could not understand this quiz question. I would appreciate > if someone could help me understand what is it asking me to > do. I dont need the answer but just the right direction to > look at.
Hello. First of all, as i look over this "script template" that your instructor has supposedly provided, i am disgusted by the abysmal formatting. I'm not sure if what you provided here is an exact replica, or something that you have modified, but in either case, a little bit of proper formatting can go a loooooong way towards readability. For instance, When writing in natural languages (such as English), we utilize common structural elements and rules so that our text will be presented in manner that is recognizable to most readers. A few of these "high level structural components" include _spaces_, _sentences_ and _paragraphs_. And when writing code, we also utilize a "common structure". And one of the most important components of this "common structure" is the use of vertical whitespace. By properly utilizing vertical whitespace, we can separate the "paragraphs" of our code (aka: classes and functions) so that reading the code will be more intuitive. Of course, Structuring code is far more complicated than simply creating "visual buffers zones" around classes and functions, and many hours have been spent debating what is proper, and what is not. But being that in the "realms of the OOP paradigm" classes and methods are the most fundamental elements, it should come as no surprise that mastering the formatting of these elements is a vital first lesson. Now, Even though there is something of an "ideological war" raging as to exactly how much vertical whitespace should be used, and _where_ it should be used, most programmers will agree that the following example is acceptable. A common style is to place *ONE* vertical whitespace between each method in a class,and two vertical whitespaces between the classes themselves. Observe the following... ## BEGIN: READABLE CODE EXAMPLE ## class Location(object): """DOCSTRING MISSING!!!""" 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): """DOCSTRING MISSING!!!""" def __init__(self, center_loc): self.center_loc = center_loc def __str__(self): return str(self.center_loc) 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[n *INSTANCE* of] 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[n *INSTANCE* of] 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 ## END: READABLE CODE EXAMPLE ## But what is most important to remember here is _not_ so much the _number_ of spaces used, but that the number is greater than _zero_, and that the spacing is _consistent_. For instance: if one feels that two spaces between methods is more desirable then that is okay, but, one should maintain the two space buffer between *ALL* methods in the script *AND* furthermore, expand the buffer between classes to four spaces -- because consistency is the key! But this code is not only lacking an intuitive format, it is also lacking an intelligent design. For instance: this object model is just begging for a "Tent object" with the Location being an attribute of each individual "Tent". Because it makes absolutely no sense for the MITCampus interface to present an "add_tent" method that expects a Location object as argument. This is illogic! Because locations are *NOT* Tents! Observe the following. ## BEGIN: SCHOOLING OF THE IDIOT PROFESSOR ## class Tent(object): def __init__(self, location): if not isinstance(location, Location): raise Exception('Expected an instance of Location!') self.location = location def upsticks(self, x, y): self.location.move(x, y) ## END: SCHOOLING OF THE IDIOT PROFESSOR (for now...) ## Now we have a proper representation of the "players" in this "game". And should it become necessary, at some point in the future, the "Tent" class can easily be extended to include such natural attributes as "name" and/or a "number of occupants" (which, depending on the needs of the model, "occupants" could be represented using a simple integer value (aka: tally) or a whole new Occupant class can be created to represent each individual occupant of the Tent.) I'm sorry to be one to inform you, but judging from the evidence presented here, your professor is not qualified to teach OOP principles. If One is to master the OOP paradigm, One must always construct an object model utilizing a design that, first and foremost, favors an ease of extensibility. However, your professor has neglected to follow this most fundamental of design considerations, thereby, rendering this lesson to be nothing more than another fine example of the blind leading the blind. Which in today's abysmal academic atmosphere, is far more common than we'd care to admit. But do not allow your unfortunate academic circumstances to discourage you. For although we have little control over who will be our instructors, or our superiors, we will always maintain control over own *OWN* capacity to learn. And if we are determined to become great students of knowledge (which i hope you are), then we must adopt an aggressive attitude to seek out knowledge in diverse places, if necessary, utilizing our sheer "force of will" alone. So if our instructor is incompetent (as they all to often are), then we will circumvent that instructors, violently kicking down the doors of hidden knowledge, if necessary, with the focused resolve that we will not be denied the knowledge for which we, as human beings, deserve. The point i'm trying to make here (with my dissection of your professor's incompetence), is that if you want to become competent at anything (not just writing code), you must realize that no one can _teach_ you anything. All an instructor can ever hope to do is to _lead_ you in a general direction, and _hope_ that you will gleam the valuable insights along the way. There are vast online sources where one can study a particular field, and unlike the formal classroom setting where you are limited by the competence and dogma of a particular instructor, online resources allow you to learn at rate that is comfortable to you, but more importantly, you will be exposed to many diverse opinions and methods of solving problems that are just not available in the orthodox setting of the "despotic classroom". And although, to gain your degree, you may have not choice but to "play along" with this unqualified professor, your knowledge need not be limited by the incompetence of the aforementioned idiot . Contrary to popular belief, i don't participate in online communities to help others, no, helping others is a secondary, and sometimes merely a consequence, of me developing my own analytical skills. Participating in online communities is sort of like a classroom, except that the "environmental motivation to excel" is not a result of dictates, but of "competition between the members". And it should be understood that it is the _competitive_force_ which injects energy into the social equation, allowing the cream to rise naturally to the top. This is how our Universe operates, and the fruits of success are all around us. Because any system that forsakes the unlimited energy source for which competition provides, can ever only hope to achieve mediocrity. The "ministries of education" are where the intellectual potential and the innovative spirit of a young mind goes to die. Please don't allow yourself to become a victim of this malevolent indoctrination. -- https://mail.python.org/mailman/listinfo/python-list