Answers & Solutions 1
Lesson 1.2 Solutions

- Before a variable can be used it first needs to have a value. In other words, without a prior assignment, the expression x1 is undefined and the error is expected.
- After a value is assigned to x1, expression x1 is well-defined.
- Notice how 6! = 5! * 6. And 7! = 6! * 7. This allows us to reuse the previously computed values.
- Notice here, that variable names can be quite long. It is a good coding practice to use descriptive names for the variables, so that your code is easy to read – by you or by somebody else.
Comments
You may have noticed that the screenshot of Python shell window above contained some red lines starting with #. These are called comments. Essentially, anything after a # is ignored by Python shell and not sent to Python interpreter. We will talk more about comments when we start writing actual Python programs.
Autocomplete
You may have gotten slightly annoyed with the long variable names. Who is supposed to type such long names over and over again? Fortunately, both the Python Shell and the Python editor come with a feature called autocomplete. Try it out – in the Python Shell window from before, type ag and then Ctrl-space. You should see a list of options that (kind of) match your string. You can see that age_difference is selected as the best choice. Hitting the Enter key will replace ag with age_difference. Amazing, isn’t it?

Lesson 1.3 Solutions

Quiz Answers
- Question 1: c. Python is an interpreted high-level programming language.
- Question 2: a. and d. High-level interpreted programming languages are translated to machine language one statement at a time so that computers can understand them.
- Question 3: b. In Python shell (and in Math), 3 + 4 * 5 = 3 + (4 * 5) = 23.
- Question 4: c. First, 5 is assigned to x. Then -2 is assigned to x overwriting the previous value. That means that x + 10 = -2 + 10 = 8.