Well, for this week's class, we learned a little bit of assertion, talked a little bit of A3, and function tracing(exciting isn't it)!
Assertion is just checking whether the user has inputed a result which may cause error in the function or not. As helpful as it may sounds, it can cause a little problem on function run times. Because it is checking every input on whether it is a assertion error or not, it has increased the run time of the functions significantly, which may not be a problem for some cases, but a disaster when it really eats away your time.
Another thing we covered this week in class is tracing functions, like the one below. Now, without copy and pasting it to see what the output is, take some time to really think about how it works. What would print(h(1)) output in the python shell(answer at the end of the blog)? It is really interesting right?
N = 5
M = 2
def f(N):
return M * g(N + 1)
def g(N):
return M * N
def h(N):
return f(g(N))
if __name__ == '__main__':
print(h(1))
It is really shocking me how much time to have to spend on your own just to play around in the python shell, and how much stuff you can actually learn from it. Learning by yourself is a big part of this course and hopefully I will see you next week on how the class is going.
Oh and one more thing, the answer is 12, it would carryout the g(1) in the f(g(1)) first which returns 2, and then f(2) which is M * g(3), g(3) would return 6, and M(which is 2) times 6 is 12. Do you get it now?