Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

@Screech: Continuing from "Having trouble with Classes" post. Screech: I read your attached Run works and the coding is excellent. You must have other talents up your sleeve. There is NO WAY, I repeat NO WAY I could accomplish that assignment just learning what I picked up from Codecademy, "How to Think Like a Computer Scientist" and the coding hints in & You have an "if" statement and y-height and other important, clever coding tricks. No way we learned that from the Gentle Intro to Python course. A genius or did you study how to do this for 25 hours?

MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
See more answers at
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly


Get your free account and access expert answers to this and thousands of other questions

@JohnM is right, I can't do this either. I don't even want to see a coded solution, but I do want some idea of what the best way to go about it is. All I get so far is that I'm supposed to create a car1 object that takes 5 arguments and is of class Car. But I don't really see how I'm allowed to include an argument called Point(50,50). I'm still working on it, if I have a breakthrough I'll say so.
I'm a retired programmer. Come in with considerable experience in C, some C++. Really love Perl, but had no Python experience before. Someone in the know might see that my coding style resembles Perl. exchaoordo If I can assist, post what you have or how you are thinking of attacking the exercise. I'll take a look and see if I can offer suggestions with an explanation of why one approach might be better or not.
Thanks Screech. My problem throughout this OO stuff has been figuring out how I link the object from one class (e.g. Wheel) to an object from another class. In my mind I would have this thing that draws a wheel and a thing that draws a rectangle. (which this problem gives us). I would create a class called Car and then have two wheel instances and one rectangle instances that are Arguments? of the Class, Arguments of the instance my_car? Methods from those objects that I use in the Car? That's what I don't get. If you can explain that in plain English I'll make more progress. Right now I'm just breaking this down into tiny parts and trying to get each to work.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Could be that the Car was a little too much for the brief exposure to OOP that this course provided.. But to avoid getting confused by inheritance, it may help to keep two things in mind when dealing with objects. If you can say that a class IS A something, then its likely that the class is going to inherit. So, the Car class you want to create IS A special kind of rectangle. When you create it, it will inherit from the Rectangle class and have the same capabilities as the Rectangle (in But, if you can say that a class HAS something, then it probably not inheriting that something. Instead, you are augmenting the class by add some characteristics or capabilities. In the case of the Car class, the Car HAS Wheels. The Car is not a Wheel. Since a Rectangle does not have wheels, we will have to add this capability to the car class. So, in the __init__() function for the Car class, we have to do some customizing by creating two Wheel objects. If you know where to put the wheels on the Car/Rectangle, then creating the two Wheels is a simple as picking names for them in the Car class and assigning Wheel to these name. self.wheel1 = Wheel( arguments to create wheel) self.wheel2 = Wheel( arguments to create wheel) I found it confusing, at first, and I still make a mistake occasionally trying to remember when to use and when to leave off the self. If you use it becomes part of the class. If you leave off the self, then its a temporary name which disappears at the end of the method. The name disappears, but the thing it pointed to might live on if you assigned it to some other name or made it the return value from the method. Although the Car HAS a Rectangle and two Wheels, these need not be created in advance. The Car's __init__() method can just as easily create the Rectangle and the Wheels if provided with the information it needs.
@Screech: Aha, I knew it. You had lots of prior programming experience. Me: Nothing. My thanks to you for sharing with us your coding insights. Your "If you use it becomes part of the class. If you leave off the self . . ." is a golden nugget, and worth stopping to ponder again and again as we (or at least I) study Python Classes. This comment alone or something similar should have been part of the course. So, again, many thanks. On the other hand, your "Although the Car HAS a Rectangle and two Wheels, these need not be created in advance . . ." comment is a bit mysterious. It sounds like you're saying that for the homework we could have forgotten about inheritance and just done everything from scratch. If yes, isn't this true in all cases, and if so, what's the point?
@Screech again: Too bad OpenStudy doesn't distinguish between Best Response and Great Response. You delve into a few wonderful abstractions to answer my post. Presumably others are capable of rendering abstractions, which would theoretically result in no "Best" but lots of "Greats." Well, maybe I'll wait a day or two and if no one chimes in with something equally good or better, which is unlikely, I'll give you a "Best." Meanwhile, I see that @exchaoordo is sharing some of my frustrations.
@Screen and your file: If I may, some questions about your code: 1) uleft_y = axle1.y - height: How did you even start to think about this subtraction? I don't think I would have got this in a million years. 2) win.after(100, self.animate, win, dx, dy, n-1): Again, I'm interested in your thought process. How did you know something like self.animate was necessary. And even more mind-blowing for a novice like me, your use of "animate" indicates you are calling the function inside the function, something we've never learned in Gentle Intro to Python. I can't even begin to figure that one out.
Darn, cannot edit comments. I meant @Screech, not @Screen. Sorry.
@screech Thanks so much again for helping out! We're digging through all of the comments from the first round now, but if you see some clear areas where the resources we used aren't providing enough information to complete assignments, please do let us know. Even better, if you know of supplementary resources we should be pointing to, call them out. When our test group ran through the course, only the experienced programmers among us got to the latter weeks, and it seems like having coding experience makes a difference in the final assignments.
@MOOC-E: I appreciate your honesty. In effect what you're saying is that Gentle Intro to Python is not so Gentle -- in fact, hopeless -- in Weeks 7 & 8 for those of without coding experience, yes? One of the things you should have added is about 10 practice lessons on coding animated objects and lots and lots of practice on manipulating function parameters inside Classes and inherited Classes BEFORE you ask us to construct something like a moving car in the exercise. If that kind of practice had been available at Codecademy people like me would have been Python superstars by now. For people like me still hanging on with their nails in Week 7, I'm keeping my fingers crossed and hoping you/Screech someone can come up with some quick-fix intermediate practice lessons in order to help us get over the hump of Weeks 7 and 8. Otherwise, we're pretty much reduced to reading the completed etc. code of Screen and others, without any deep understanding or any understanding of future practice use.
@MOOC-E glad to see you're monitoring this, and @Screech, I gladly give you a "Best." I'm still working on this problem and aim to nail it down. I've gone into look at the code of and I tried simplifying and simplifying so I could understand where my problem really lies. It seems as if I could make a class Car(Rectangle) and then have an __init__ that adds the two wheels, as Screech said. I just can't get my head around how to do that. Here I've simplified down to using directly, I think, but this is way off:class Car(Rectangle): def __init__(self, frontWheel, backWheel, body): self.frontWheel = Circle(Point(50,50), 10) self.backWheel = Circle(Point(100,50,10)) self.body = Rectangle(Point(30,20), Point (120,50)) myCar = Car(Point(10,30)) Thanks for all the help, still trying.
Oh, and I lied a bit: I did do some GW Basic and machine language shape tables when I had an Apple II+ with a cassette recorder for storage in, what 1979? Now THAT was fun.
MOOC-E I just get the sense that a LOT of people are having problems grasping the elegance and simplicity of O-O basics to attack some of the exercises. For those with little programming background or experience solely in procedural languages (like C), O-O can require rethinking how you look at programming. Maybe some additional time spent on O-O with some more graduated exercises. exchaoordo Use the code (from wheel import *) and instead of creating Circle objects, create Wheel objects. This reuses the code you debugged in a previous exercise. That being said, I noticed that in my own Car code, I neglected to inherit the Car from Rectangle. I have to take a step back and re-think why I did that. Maybe it was just an oversight on my part.
Here's a basic question: In one or two of the "How to Think Like a Computer Scientist" chapters on Classes it mentions setting a default for the parameter in the initializing statement. For example, def __init__(self, x, y=2, z=" ") or some such. What is the purpose/reasoning of these defaults? I find no discussion in "How to" nor practice at Codecademy nor discussion of any length in online Python documentation.
@JohnM, I want to really understand your question. If you don't have a __init__ you just have a class where you declare that any object of that class has to take, say 3 integers as an argument. Providing defaults would seem to say, "If no arguments are given for, say, Integer #3, just use what is in the class __init__ statement." But -- and here's the key -- you can't actually instantiate a new object WITHOUT giving it the proper arguments. Hence: What is the point of these __init__'s? Now, there is some discussion of arguments existing at the class level rather than the object level (I think they get called "fields" for classes and then "arguments" for objects.) and the point is made that either each object SHARES the same "field" or each object creates its own version of the argument even if the argument is always the same. But that doesn't answer your question, does it? Great question! I think I'll only learn this if we figure out the answer together, not if someone again tells me about fields and arguments.
@exchaoordo: I'd like to help or collaborate, but I'm afraid I don't understand your question. My post is not about the reason for having __init__. My post is about the reason for creating parameter defaults in the initializing statement. If you read, I think (recalling from memory), the "How to Think Like a Computer Scientist" chapters 15 & 16 you will see the use of defaults to create card games, which we (MOOC students) did not practice at Codecademy or anywhere else. Unfortunately, the reason and use of these defaults is not clear (at least not to me). I think you are raising a separate issue.
JohnM I think I tried it out before attempting to animate to see how the wheels would look on the Rectangle. I chose to use the "axle" meme in order locate where the wheel centers would be. As far as the use of win.after, I think dug into the module to try to dispell some of the smoke and mirrors. I don't pretend to understand it completely, but I managed to get the car to move and late on, to play Tetris in the final project.
We at OpenStudy recognize the Awesomeness of Screech. Officially!

Not the answer you are looking for?

Search for more explanations.

Ask your own question