On Sep 15, 2018 1:50 PM, "Alister via Python-list"
wrote:
>
> On Sat, 15 Sep 2018 17:08:57 +, Stefan Ram wrote:
>
> > I gave two different functions:
> >
> > def triangle():
> > for i in range( 3 ):
> > forward( 99 ); left( 360/3 )
> >
> > def rectangle()
> > for i in range( 4 ):
> > forward( 99 ); left( 360/4 )
> >
> > , and the exercise was to write a single definition for a function
> > »angle( n )« that can be called with »3« to paint a triangle and with
> > »4« to paint a rectangle. Nearly all participants wrote something like
> > this:
> >
> > def angle( n ):
> > if n == 3:
> > for i in range( 3 ):
> > forward( 99 ); left( 360/3 )
> > if n == 4:
> > for i in range( 4 ):
> > forward( 99 ); left( 360/4 )
> >
> > Now I have added the requirement that the solution should be as short
> > as possible!
My candidate for shortest expression:
[( forward( 99 ), left( 360/n)) for x in 'a'*n]
>
> seems a good exercise & you are breaking the students in step by stem
> which is also good
> get something that works, then make it better
>
> i would suggest instead of the new requirement to be make it a short as
> possible make it work with ANY number of sides.
>
>
>
>
> --
> Max told his friend that he'd just as soon not go hiking in the
> hills.
> Said he, "I'm an anti-climb Max."
> [So is that punchline.]
> --
> https://mail.python.org/mailman/listinfo/python-list
--
https://mail.python.org/mailman/listinfo/python-list