Earlier last week we learned about the 'ternary if'. With this mathod, we can combine the 'else if' code into a single line. It can help us to make our code easier to read.
For example:
if temp >= 15:
outcome = 'Hot'
else:
outcome 'cold'
can be combine into:
outcome = 'Hot' if temp >= 15 else 'Cold'
Later we were introduced to the Tree function. We learned about the definations of the term Tree such as 'leaf : a node with no child' and 'internal node: a node with one or more children'. These definations are easy to understand after I built a Tree by myself for exercise. In order to use the Tree efficiently, we need to fully understand how 'recursion' works, because we need to use 'recursion' in each subtree. Hence it will be very confusing to deal with a Tree class if we are not used to use recursion.
In the Lab7, we did the exercise about implement the recursive function respect to the Tree class. My partner and I were struggled on the 'implement list_leaves', because both of us were not familiar with using recursive function. We did not finish all the exercises in the Lab, so I believe we need to practise more on these functions at home.
没有评论:
发表评论