[Edu-sig] turtle: properties instead of setters/getters ?

Jurgis Pralgauskis jurgis.pralgauskis at gmail.com
Mon Apr 27 17:19:54 CEST 2015


Hi,

turtle module is nice way to introduce to Python,
but, if I want to increase x by 10, I have to write

t.setx( t.xcor() + 1)

which is uglier (and not beginner friendly) than common:
t.x = t.x + 1

beginners tend to forget () after xcor and so on...

This could be achieved with  several property
<https://docs.python.org/3/library/functions.html#property>/decorator lines
Would it be possible for Py 3.5? :)


ps.: I teach programming games,
and more robust expressions (for collision checking) would look cleaner:
if ball.x-5 > box.x-10   and  ball.x+5 < box.x+10:
     ball.x =100

instead of
if ball.xcor()-5 > box.xcor()-10   and  ball.xcor()+5 < box.xcor()+10:
     ball.setx( 100 )

pps.:
I don't know how would default turtle instance behave
could I then write     x = x + 1
instead of          setx( xcor() + 1)
?


-- 
Jurgis Pralgauskis
tel: 8-616 77613;
Don't worry, be happy and make things better ;)
http://galvosukykla.lt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20150427/04cf34bb/attachment.html>


More information about the Edu-sig mailing list