Intro to coding with a Jupyter notebook

This is a Jupyter notebook. It allows you to type text, format it with headings and links, insert images, and have separate cells for code. You can click the "play" icon above (or shift+ENTER) to execute a cell and go on to the next one. You can also edit the code and run it again to see how the output changes.

Click on this cell, then press shift+ENTER.

Next, try executing the following cells.


In [1]:
# This is how to add.
2+2


Out[1]:
4

In [2]:
# This is a "comment"
# Starting the line with # tells the program not to read this
5-4


Out[2]:
1

In [3]:
# the following lines "define variables"
a = 4
b = 3

# If you're used to other languages, Python doesn't need the "print" command
# the next line displays the result
a+b


Out[3]:
7

In [4]:
c = a*a
c


Out[4]:
16

In [5]:
# Can you figure out what this operation is?
d = b**a
d


Out[5]:
81

Spend a few minutes editing some of the code above. You can re-execute a cell by pressing shift+ENTER.

  • Edit some code to do a different calculation
  • Add a comment in a code cell to explain what the code does
  • Figure out what that last calculation does

You can save by clicking on the disk icon in the top toolbar.
To download a static pdf version (for printing or to show someone without Jupyter installed), go to File > Download as > PDF via LaTex.
To start over from scratch: on the toolbar above click Kernel > Restart and Clear Output.

Markdown

This is a markdown cell which contains markdown text. That's text that isn't read as Python code. Instead, you can format markdown text to look nice. If you double-click on a markdown cell (like this one) you can see the code that formats this text. It's pretty simple.

Read about formatting the markdown text in a cell, like this one, or go to Help > Markdown > Basic Writing and Formatting Text.

Now, try writing some markdown text of your own. Include:

  • a heading
  • a hyperlink
  • a bulleted list

In [ ]: