Yiyang's Chapter 3 Exercise

by Yiyang Shi

20 Jan 2016

Here is Exercise 1:

Here is Exercise 2:

Here is Exercise 3:

Reflection:

I noticed that the “if-if-if-…” expression can serve the same purpose as the “if-elif-elif-…” expression. I wonder if one is better than the other. My guess is the “if-if-if” expression is better because once the “if” statement is determined as false, the computer goes to the next “if” without having to “memorize” anything. For the “if-elif-elif” case, the range of the “elif” is the whole range minus the “if” range. So the computer has to find out the range first and then determine if a statement is true or false. Not sure if my guess is correct.

Find Yiyang Shi on Twitter, Github, and on the web.