2015年1月29日星期四

Things from these weeks, and also about assignment 1 and the recursions.

CSC148 started scarily, especially with its scary assignment 1.
To be honest, class was the part which I didn't really understand during CSC108H, so designing classes was really a challenge.
But after a few weeks of study, I think I have a way better understanding on classes than before. Therefore, I do hope do get a nice mark on my first assignment. XD



Recursion
Recursion is a function(or maybe later a method, but anyway a way of doing things, i will always refer it as 'function' in the rest of this post) which calls itself.
When we use recursion:
1. when we can solve a big problem by solving its components using with the same concept.
2. especially when we don't know how many times we need to call the function. (We don't know how deep we need to go.)

the typical appearance of a recursion is:
def f(L): #f is a program and L is the input
    if  isinstance(L,x): #x refers to a type, it could be anything.
        #thing here could vary, but anyway it calls f on the components of L.
    else:
        return XXX #return the basic value of this function.


Things from assignment 1:
- doctest doesn't test on print or input, so need to be careful for some potential mistake there.
- when printing, the white space due to indention will be printed as well, what I did to solve this problem is to delete the indention.

没有评论:

发表评论