However, tracing is of course very easy compared to actually designing a recursive function. In the end of lab#4 their were some exercises on designing our own recursive functions. It felt much more challenging. I felt it is very important to think systematically when designing such functions. The functions we ran into generally break the problem into two parts--the "if isinstance(a, b) " statement is used when the parts in the arguments needs to be plugged into the function and go into recursion; the "else" statement is usually when the some parts of the argument needs no more recursions. and after some slight modification (such as adding 2 to the number or 'ox' to a string), will be stored in a list as part of the output. So when designing recursive functions, we must decide when the function should keep on taking arguments inside arguments ; what kind of value reached would no longer need to run the recursive function, and what should we do to these values to give the correct final output.
No comments:
Post a Comment