Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JohnM

  • 2 years ago

Week 7 - Having trouble with classes I don't see any questions posted on Classes even though the Gentle Python course has ended. Did others finish? For example, did anyone do Exercise 4.1 – Inventing The Wheel (from the MIT homework)? I had no luck getting the wheel to move. I'm not sure where to place the code mentioned in the homework assignment.

  • This Question is Open
  1. andrew.m.higgs
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    How far did you get? Can you post what you have done so we can take a look?

  2. JohnM
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I have no idea how to execute def animate(). Variants of the execution command contained in the below code don't seem to work. from graphics import * class Wheel(): def __init__(self, center, wheel_radius, tire_radius): self.tire_circle = Circle(center, tire_radius) self.wheel_circle = Circle(center, wheel_radius) def draw(self, win): self.tire_circle.draw(win) self.wheel_circle.draw(win) def move(self, dx, dy): self.tire_circle.move(dx, dy) self.wheel_circle.move(dx, dy) def set_color(self, wheel_color, tire_color): self.tire_circle.setFill(tire_color) self.wheel_circle.setFill(wheel_color) def undraw(self): self.tire_circle .undraw() self.wheel_circle .undraw() def get_size(self): return self.tire_circle.getRadius() def get_center(self): return self.tire_circle.getCenter() # Define a main function; if you want to display graphics, run main() # after you load code into your interpreter def main(): # create a window with width = 700 and height = 500 new_win = GraphWin('Wheel', 700, 500) # What we'll need for the wheel... wheel_center = Point(200, 200) # The wheel center is a Point at (200, 200) tire_radius = 100 # The radius of the outer tire is 100 # Make a wheel object new_wheel = Wheel(wheel_center, 0.6*tire_radius, tire_radius) # Set its color new_wheel.set_color('red', 'black') # And finally, draw it new_wheel.draw(new_win) def animate(self, win, dx, dy, n): if n > 0: self.move(dx, dy) win.after(100, self.animate, win, dx, dy, n-1) # Run the window loop (must be the *last* line in your code) new_win.mainloop() # Comment this call to main() when you import this code into # your car.py file - otherwise the Wheel will pop up when you # try to run your car code. main() animate(win, 1,0,5)

  3. JohnM
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Addition to the above: From Codecademy practice to Ch.16 in "How to Think Like Computer Scientist" to now something like this in the MIT homework strikes me as a big leap. Week 1 to 6 of Intro to Gentle Python/MOOC more or less made sense with the materials we were given by MOOC. Now, many of the concepts concerning the above code are not explained in any of the Week 7 MOOC study materials. For beginners like me, I don't know how the heck we're expected to proceed. Everything up to Classes in this course can be supplemented by Googling for Python help. But I can find very little above importing graphics modules to get them to work with Classes, so I'm at a loss. Let's just call it the MOOC version of Skyfall.

  4. andrew.m.higgs
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Should def animate not be part of your class Wheel? What error messages are you getting? I think with a rough glance over the code that it will probably relate to self.move not existing or some such. Week 6 had us reading 3 chapters on classes. This should be building on that. But yes there were times when I felt that things had changed fairly quickly too. I thought that I had lost focus a bit.

  5. Screech
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    OK, here is my car with wheels that move it across the window. should be in same directory as graphics.py and wheel.py. Make sure that you follow the directions in wheel.py and comment out the last line ( the call to main() )

    1 Attachment
  6. JohnM
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @Screech: I think you're one homework lesson ahead of me. I will look at your attachment later. I'm first trying to get the wheel to move in wheel.py. The car/wheel movement is, I believe, the next homework assignment, which I haven't yet examined. @Andrew Higgs: "Should def animate not be part of your class Wheel?" What you say sounds about right, now that I think about it and study other Python issues on the Web. Unfortunately, the MIT instructions (in 6.189 Homework 4) are unclear They state both "#add any functions or classes you might define here" and "# add your code below this point". I was concentrating more on the latter (since that's the homework instruction), and now realize that def animate() probably has to be included with the other defs, while the code to run def animate() has to go below new_win = GraphWin.

  7. JohnM
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Odd!!?? I just noticed that the Screech and Andrew Higgs messages, and my reply, are appearing in the Computer Science OpenStudy section. Why are these messages not being channeled to the Gentle Intro to Python OpenStudy section, which is where I placed my post and Andrew Higgs replied about 12 hours ago?

  8. JohnM
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @Screech and Andrew Higgs: OK, I managed to animate (i.e. move) the wheel in wheel.py. Success! But what new interesting, important thing have I/we learned about Python Classes? I guess we learned where to place inside a Class a) functions that define animated objects and b) some about where to place code to execute the animation, based fundamentally on the GraphWin template. Important, I guess, but is that it?

  9. Screech
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    About half the time, the Open Study comes up with some course OTHER THAN MIT 6,189. I don't know why.

  10. exchaoordo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @JohnM: here's what I did to do the animate, and I don't know any coding but what I've learned here: ## 6.189 HW 4, ex. 4.1 section 3: animate Wheel def animate(self, win, dx, dy, n): if n > 0: self.move(dx,dy) win.after(100, self.animate, win, dx, dy, n-1)

  11. KLEEDS
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    They told us at the beginning that it's an experiment! Also there are random obstacles added in order to encourage teamwork.

  12. JohnM
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @exchaoordo: Thanks. Have taken a break for about a week and will move on later. @KLEEDS: Ah, yes. Another in a long list of comments I've seen online at various programming websites, along the lines of people either passively accepting or taking perverse pride in suffering through a sado-masochistic process in order to learn programming. Such an approach would not be acceptable in learning, say, linear algebra or organic chemistry, but is de rigeur for many when learning coding.

  13. KLEEDS
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @JohnM That was intended humorously, ironically! Sorry to hear that you have been sadomasochistically subjecting yourself to long lists of bitter comments. Perhaps you could try taking up a more enjoyable hobby, like programming!

  14. KLEEDS
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    To encourage teamwork is an excellent goal. There are several ways how the MOOC team could have helped shorten the path from the weekly MOOC mail to the actual course material, and there are several helpful features that this forum could have, but it doesn't. In both cases, the added benefit inefficiency is more discussion among ourselves. That is rude to call someone passive-aggressive when you don't know the person, even if it might be true at times.

  15. exchaoordo
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hi @JohnM. I took some time off too, but am now back trying to get to Tetris and to the car animation. Did you call your animate method on your new wheel? I think your problem above is that after the ##draw it comment, you need this: #Move the wheel new_wheel.animate(new_win, 1,0,250)

  16. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.