Teaching material for Quantitative Methods track in Semester 1
Tutorial 1
Tutorial 2
Tutorial 3
Tutorial 4
Tutorial 5
Tutorial 6
Tutorial 7
Tutorial 8
First we need to setup python programming for your computer. There are two ways we can do this, either we install Anaconda or use Google Colab.
Google Colab is easier to setup, but requires an internet connection whenever you use it (and that the Colab service is available). Anaconda runs on your machine and does not need an internet connection (after it is installed). For this reason Anaconda may be more convenient and tends to run faster.
First we need to install Anaconda to setup the python programming language and jupyter notebooks on your computer.
Sign In
in the top right corner of the page.For Anaconda:
For Colab:
Sign In
in the top right corner of the page and login.File
-> New notebook
A notebook is called a “notebook” because you can use it as an electronic notebook to take notes. Before we start coding, let’s try that out…
First we tell the notebook that you want to input text instead of code. Select the box where it says Code
and change it to Markdown
1 (This is slightly different in Colab. Instead of Markdown
you need to select Text
).
You can now write text here in the cell. You can format the text to be bold, italic, headings, lists etc. To do this we type in something called “markdown”
For example, you can type this input:
and “run” the cell by pressing Shift
+ Enter
to produce this output:
Exercise 1: Try making some notes yourself. Write a todo list (either ordered or bullets) and highlight important items using bold or italic. Include a heading.
You can see some other examples here.
Now you are ready to write some code.
Exercise 2: Below the text you wrote there should be a new cell. Enter the text print("hello world")
and run the cell (make sure you have changed back to Code
instead of Markdown
)
What is the output?
Look back over the lecture slides and try to describe the different parts of the code.
You can also perform calculations using arithmetic operations, i.e., addition +, subtraction -, multiplication * and division /.
Exercise 3: Using the lecture slides, try to do the following (each in its own code cell):
Arithmetic operations also work sometimes on non-numeric data. For example, we can tell python that some data is text by using quotation marks "
or '
Exercise 4: Try the following operations with text:
Can you explain the output? Note that some of the above may produce an error!
Try inserting Markdown
cells between the code cells and enter your explanation for each
Exercise 5: Saying “Hello world” seems a little impersonal. Get python to greet you personally with the following code:
name = input("What is your name?")
print("Hello " + name)
It is important to save your notebook so that you can come back to it later.
Exercise 6: First give your notebook a meaningful name.
Right click at the top where it says Untitiled.ipynb
Change the name of the notebook to something meaningful like My_first_Notebook.ipynb
or Tutorial1.ipynb
and click Rename
. Make sure that you do not include spaces and do not delete the .ipynb
at the end.
Press Ctrl
+ S
to save the notebook.
Now can you find where this file is stored on your computer?
To submit your work each week to Canvas you need to convert the file to a format that we can read in Canvas. To find out how to do this, follow the instructions on preparing submissions.
Finally, type import antigravity
into a code cell and run it.
Now you are flying with Python.
Markdown is a way to format text using only plain text that the computer can interpret as formatting instructions. Not only does this work in notebooks, but you can also write webpages this way. (This page is written in Markdown!) ↩