Week 1: Introduction

Intended learning outcomes

By the end of this class, you will be able to:

1  General instructions

2  Familiarising yourself with the course materials

To access the course materials, navigate to the course Blackboard site


and click on "Course materials", or else navigate directly to the webpage:


Take a moment to look through the various links available on the course Blackboard site. From the home page you should see links to Dr Fletcher's office hour appointments. Click on "Discussion board" in the left-hand menu, then click on "MAS115 Python Discussion", and click on "Subscribe" to receive email notifications of questions and answers posted on the discussion board. Read the first thread on how to write posts for the discussion board.

3  Entry survey

From the home page of the course Blackboard site, click on "Entry survey". Take a few minutes to complete and submit this anonymous survey, which is designed to help the lecturers and demonstrators to understand your programming experience at the start of the course. If you haven't done much programming before, please don't worry - when designing this course, the lecturers haven't assumed any prior knowledge.

4  Google Colab

For the Python labs we will use Google Colab, a free cloud service that allows you to run and share Python code within your internet browser. If you are unable to access Google Colab, for example due to the China firewall, then you should install Python on your own computer (see Section 5 below).

Navigate to the webpage


and click on the blue "Sign in" button in the top right to sign in with your university email address and password. Select "File $\rightarrow$ New notebook" to create a notebook for this lab. Click on the notebook name in the top left (probably "Untitled0.ipynb") and change this to something like "MAS115 Python Lab Week 1".

Google Colab autosaves regularly, though you can also manually save by pressing Ctrl+S. To find where the notebook lives in your Google Drive, select "File → Locate in Drive". To export your code so it can be run in another program such as Spyder, you select "File → Download .py".

In the main window, you should see a blinking cursor in a rectangular box, with a play button to its left. This is called a code cell. At the start of this worksheet you will be executing code cells to get an immediate response from the Python interpreter. To edit a cell, click the cell then start typing. To execute a cell, click the cell then either press its play button or press Ctrl+Enter. To add a new cell, click "Insert → Code cell". You can also execute a cell and add a new cell in one go, by pressing Shift+Enter.

On these worksheets, code to be typed into a cell then executed immediately, rather than being part of a longer program, is indicated by >>>. However, you do not type in these symbols. For instance, if you see

>>> x = 3
>>> print(x)

then you should type x = 3 in a code cell, press Shift+Enter, see if the Python interpreter responds with anything, then type print(x) in the next code cell and press pressing Shift+Enter again.

Whenever you type something in, you should guess what the response will be before you press Shift+Enter. If you don't understand what is going on during the lab, please ask a demonstrator.

5  Alternatives to Google Colab

If you cannot use Google Colab for the Python labs, then instead you can download and install Python on your own computer for free. We suggest you do this by installing the Anaconda distribution of Python (version 3.8), which includes Jupyter Notebook and Spyder.

To install Anaconda, navigate to the webpage


and scroll down to "Anaconda Installers", choosing the correct installer for your operating system.

Having installed Anaconda, we suggest you use Spyder to write and edit Python programs. On the worksheets, code to be typed into Spyder's IPython console, rather than being part of a program, is indicated by >>>. Programs (no >>>) are typed in the editor rather than in the console; you can open a new file by typing Ctrl+N or via the File menu.

If you have any questions about installing Python or using Spyder, please ask these on the discussion board.

6  Simple arithmetic

To finish the lab, we will see how to use Python as a calculator to perform simple arithmetic. Here x**y means xy. Type in the following and make sure that you are happy with the responses from the computer.

>>> 7 + 3
>>> 3.2 * 2
>>> 5**2
>>> 3.4 / 2
>>> 2**0.5 - 1
>>> (3 + 4) * 2
>>> 3 + 4 * 2

Notice the difference in the last two lines: Python obeys the usual BODMAS rules. (Search the internet for "BODMAS'' if you do not know this acronym for the order of operation.)


If you have any problems with the homework then you can seek help in the following ways, both accessible via the module's Blackboard site:

In future Python labs, one homework question will be assessed online - you will find out more about this in next week's Python lab.

  1. You should finish off this worksheet before the next lab.

  2. (Optional.) During this course, we will be pointing out things related to the course that are useful or interesting. For example, the code.org website is an excellent resource for furthering programming skills. Watch this video to find out more about how useful programming skills can be:


    Next week, we will begin honing your Python programming skills!