On Mon, Apr 27, 2015 at 12:19 PM, Jurgis Pralgauskis < jurgis.pralgaus...@gmail.com> wrote:
> 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? :) > > I doubt very much that anything is going to happen with the official Turtle module unless the person that actually wrote it decides it's worth looking into. Following a suggestion you made on this list, I submitted a patch ( http://bugs.python.org/issue23660) about 6 weeks ago and no one has looked into it as far as I can tell. You could possibly write your own Turtle module, as a wrapper to the official one, using properties the way you mention. > > 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 ) > Yes, I prefer the first style too. > > pps.: > I don't know how would default turtle instance behave > could I then write x = x + 1 > instead of setx( xcor() + 1) > ? > This would not be possible: x would just be a variable, with no relation to a given turtle. At the very least, one would need to call some update() function which could look at the values of the variables in locals() and proceed from there.... But I think that this would be counter-intuitive and not a good way to teach about Python. André > > > -- > Jurgis Pralgauskis > tel: 8-616 77613; > Don't worry, be happy and make things better ;) > http://galvosukykla.lt > > _______________________________________________ > Edu-sig mailing list > Edu-sig@python.org > https://mail.python.org/mailman/listinfo/edu-sig > >
_______________________________________________ Edu-sig mailing list Edu-sig@python.org https://mail.python.org/mailman/listinfo/edu-sig