Skip to content

Instantly share code, notes, and snippets.

@john9631
Last active December 25, 2015 18:09
Show Gist options
  • Save john9631/7018013 to your computer and use it in GitHub Desktop.
Save john9631/7018013 to your computer and use it in GitHub Desktop.
MITx Week One
{
"metadata": {
"language": "Julia",
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Week One"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Starting with Hello World\n",
"\n",
"println(\"Hello World\")\n",
"println()\n",
"# Julia requires () like Python 3 and has a printing function\n",
"# print with no linefeed or println including a line feed.\n",
"# Note that println is a function so it needs the ()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Hello World\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# And then a conditional test\n",
"\n",
"variable_named_bob = 5\n",
"\n",
"if variable_named_bob < 900\n",
" print(\"Hello\", \" \")\n",
" println(\"World\")\n",
"end\n",
"\n",
"# notice no colons or brackets required but instead we have an end\n",
"# also you can use a ; instead of a new line and Julia really \n",
"# isn't worried about indentation or extra spaces so I could have\n",
"# written this instead\n",
"\n",
"if variable_named_bob < 900\n",
"println ( \"Hello World 2\" ) ; end\n",
"\n",
"# You can also use the ternary operator\n",
"variable_named_bob < 900 ? println(\"Hello World 3\") : nothing\n",
"\n",
"# and you can use short circuit evaluation\n",
"variable_named_bob < 900 && println(\"Hello World 4\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Hello "
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"World\n",
"Hello World 2\n",
"Hello World 3\n",
"Hello World 4\n"
]
}
],
"prompt_number": 7
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"and the rest of this week is about installing Python"
]
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment