Experiences with a programming exercise

Alister alister.ware at ntlworld.com
Sat Sep 15 13:49:31 EDT 2018


On Sat, 15 Sep 2018 17:08:57 +0000, 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!

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.]



More information about the Python-list mailing list