[Tutor] Help on Assignments - Turtle

Alan Gauld alan.gauld at yahoo.co.uk
Sat Jul 30 19:03:42 EDT 2016


On 30/07/16 16:28, Justin Korn via Tutor wrote:
> I have been working on these assignments for a week and a half, 
> and I can't make any progress. I also been dealing with a
> sick relative, so please help me out immediately.

While I sympathise with your circumstances we are all
volunteers here so the help you receive will be at the
speed that suits the members.

I will address your two assignments in separate mails.


> import turtle
> class turtle_Turtle():
>     ts = turtle.Screen()
>     ts.title("TurtleGTX")
>     bob = turtle.Turtle()
>     bob.shape("turtle")
>     bob.color("brown")

I'm not sure what you think this is doing but I'm
pretty sure its not what you want. You are basically
defining a couple of class variables and nothing else...

> class TurtleGTX(turtle_Turtle):

I would have expected you to inherit from turtle.Turtle
rather than turtle_Turtle. The latter has no methods and
only two class variables. So your GTX class likewise has
no inherited methods, you will need to define all of
its behaviour.

>     odometer = 0

This is a class variable meaning it is shared by all
turtles. I suspect you really want it to be an instance
attribute, which means defined within an __init__()


>     def forward(x):

The first parameter of a class method is usually called
self because it will refer to the active object. In this
case your x will be the object, whereas I think you want
it to be the distance to move? But if so x is a bad choice
of name since it implies horizontal direction only

>         if (x >= 0):
>             i = 0
>             while (i < x):
>                 self.fd()
>                 odometer += 1
>                 i+=1

This is a horribly inefficient way of saying

if x>=0:
  self.fd(x)
  odometer += x

But it won't work because
a) You didn't inherit from turtle so you don't have a fd() method
b) Even if you had it requires an input value for its distance
so should be self.fd(1)


>         else:
>             i = 0
>             while (i > x):
>                 self.bk()
>                 odometer +=1
>                 i-=1

Again a very inefficient alternative to

else:
   x = -x
   self.bk(x)
   odometer += x

>         print ("Odometer is", odemeter)

Do you really want to print that every time the turtle moves?

> my_turtle = TurtleGTX()
> my_turtle.foward()

You misspelled forward and failed to give it an x value.
Please send real code and/or any error messages. This code
could never have run so you should have errors.



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list