Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions 1. Getting started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
},
"outputs": [],
"source": [
"my_name = \"Jane\"\n",
"typeof(my_name)"
"😺 = \"smiley cat!\"\n",
"typeof(😺)"
]
},
{
Expand All @@ -134,7 +134,7 @@
},
"outputs": [],
"source": [
"my_answer = my_name"
"my_answer = 😺"
]
},
{
Expand Down Expand Up @@ -261,7 +261,8 @@
"source": [
"### Exercises\n",
"\n",
"1.1 Look up docs for the `convert` and `parse` functions."
"#### 1.1 \n",
"Look up docs for the `convert` function."
]
},
{
Expand All @@ -277,7 +278,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"1.2 Assign `365` to a variable named `days`. Convert `days` to a float."
"#### 1.2 \n",
"Assign `365` to a variable named `days`. Convert `days` to a float."
]
},
{
Expand All @@ -293,18 +295,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"1.3 See what happens when you execute\n",
"#### 1.3 \n",
"See what happens when you execute\n",
"\n",
"```julia\n",
"convert(Int64, '1')\n",
"convert(Int64, \"1\")\n",
"```\n",
"and\n",
"\n",
"```julia\n",
"parse(Int64, '1')\n",
"```\n",
"\n",
"What's the difference?"
"parse(Int64, \"1\")\n",
"```"
]
},
{
Expand Down
68 changes: 51 additions & 17 deletions 2. Strings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,30 @@
"source": [
"name = \"Jane\"\n",
"num_fingers = 10\n",
"num_toes = 10\n",
"\n",
"num_toes = 10"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"println(\"Hello, my name is $name.\")\n",
"println(\"I have $num_fingers fingers and $num_toes toes. That is $(num_fingers + num_toes) digits in all!!\")"
"println(\"I have $num_fingers fingers and $num_toes toes.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
" println(\"That is $(num_fingers + num_toes) digits in all!!\")"
]
},
{
Expand All @@ -149,7 +169,8 @@
},
"outputs": [],
"source": [
"string(\"How many cats \", \"are too many cats?\")"
"s3 = \"How many cats \";\n",
"s4 = \"are too many cats?\";"
]
},
{
Expand All @@ -160,14 +181,7 @@
},
"outputs": [],
"source": [
"string(\"I don't know, but \", 10, \" are too few.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also use `*` or string interpolation!"
"string(s3, s4)"
]
},
{
Expand All @@ -178,8 +192,14 @@
},
"outputs": [],
"source": [
"s3 = \"How many cats \";\n",
"s4 = \"are too many cats?\";"
"string(\"I don't know, but \", 10, \" are too few.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also use `*` or string interpolation!"
]
},
{
Expand Down Expand Up @@ -210,21 +230,35 @@
"source": [
"### Exercises\n",
"\n",
"2.1 Create a string that says \"hi\" 1000 times."
"#### 2.1 \n",
"Create a string that says \"hi\" 1000 times."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2.2 Add two numbers together within a string."
"#### 2.2 \n",
"Declare two variables\n",
"\n",
"```julia\n",
"a = 3\n",
"b = 4\n",
"```\n",
"and use them to create two strings:\n",
"```julia\n",
"\"3 + 4\"\n",
"\"7\"\n",
"```"
]
},
{
Expand Down
37 changes: 29 additions & 8 deletions 3. Data structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@
"source": [
"## Dictionaries\n",
"\n",
"If we have sets of data related to one another, we may choose to store that data in a dictionary. A good example is a contacts list, where we associate names with phone numbers.\n",
"If we have sets of data related to one another, we may choose to store that data in a dictionary. We can create a dictionary using the `Dict()` function, which we can initialize as an empty dictionary or one storing key, value pairs.\n",
"\n",
"Syntax:\n",
"```julia\n",
"Dict(key1 => value1, key2 => value2, ....)```"
"Dict(key1 => value1, key2 => value2, ...)```\n",
"\n",
"A good example is a contacts list, where we associate names with phone numbers."
]
},
{
Expand Down Expand Up @@ -537,8 +539,14 @@
"source": [
"### Exercises\n",
"\n",
"3.1 Create an array, `a_ray`, that is a 2-element 1D array of 1-element 1D arrays, each storing the number 0.\n",
"Index into `a_ray` to add a second number, `1`, to each of the arrays it contains."
"#### 3.1 \n",
"Create an array, `a_ray`, with the following code:\n",
"\n",
"```julia\n",
"a_ray = [1, 2, 3]\n",
"```\n",
"\n",
"Add the number `4` to the end of this array and then remove it."
]
},
{
Expand All @@ -554,7 +562,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"3.2 Try to add \"Emergency\" as key to `myphonebook` with the value `911`. Try to add `911` as an integer rather than as a string. Why doesn't this work?"
"#### 3.2 \n",
"Try to add \"Emergency\" as key to `myphonebook` with the value `string(911)` with the following code\n",
"```julia\n",
"myphonebook[\"Emergency\"] = 911\n",
"```\n",
"\n",
"Why doesn't this work?"
]
},
{
Expand All @@ -570,7 +584,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"3.3 Create a new dictionary called `flexible_phonebook` that has Jenny's number stored as a string and Ghostbusters' number stored as an integer. "
"#### 3.3 \n",
"Create a new dictionary called `flexible_phonebook` that has Jenny's number stored as an integer and Ghostbusters' number stored as a string with the following code\n",
"\n",
"```julia\n",
"flexible_phonebook = Dict(\"Jenny\" => 8675309, \"Ghostbusters\" => \"555-2368\")\n",
"```"
]
},
{
Expand All @@ -586,7 +605,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"3.4 Add the key \"Emergency\" with the value `911` (an integer) to `flexible_phonebook`."
"#### 3.4 \n",
"Add the key \"Emergency\" with the value `911` (an integer) to `flexible_phonebook`."
]
},
{
Expand All @@ -602,7 +622,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"3.5 Why can we add an integer as a value to `flexible_phonebook` but not `myphonebook`? How could we have initialized `myphonebook` so that it would accept integers as values?"
"#### 3.5 \n",
"Why can we add an integer as a value to `flexible_phonebook` but not `myphonebook`? How could we have initialized `myphonebook` so that it would accept integers as values?"
]
},
{
Expand Down
58 changes: 10 additions & 48 deletions 4. Loops.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,6 @@
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that we could replace `in` with either `=` or `∈`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"for n = 1:10\n",
" println(n)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"for n ∈ 1:10\n",
" println(n)\n",
"end"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -228,7 +195,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In the next example, we embed an array comprehension in a `for` loop, generating addition tables of growing size."
"### Exercises\n",
"\n",
"#### 4.1 \n",
"Write a loop that prints the squares of integers between 1 and 100."
]
},
{
Expand All @@ -238,27 +208,18 @@
"collapsed": true
},
"outputs": [],
"source": [
"for n in 1:10\n",
" A = [i + j for i in 1:n, j in 1:n]\n",
" display(A)\n",
"end"
]
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercises\n",
"\n",
"4.1 Create a dictionary, `squares`, that has integer keys from 1 to 100. The value associated with each key is the square of that key. Store values associated with even keys as integers and values associated with odd keys as strings. For example,\n",
"#### 4.2 \n",
"Add to the code above a bit to create a dictionary, `squares` that holds integers and their squares as key, value pairs such that\n",
"\n",
"```julia\n",
"squares[10] == 100\n",
"squares[11] == \"121\"\n",
"```\n",
"\n",
"(You don't need conditionals to do this!)"
"```"
]
},
{
Expand All @@ -276,7 +237,8 @@
"collapsed": true
},
"source": [
"4.2 Use the `fill` function to create a `10x10` matrix of `0`'s. Populate the first ten entries of the matrix with the index of that entry. Does Julia use column-major or row-major order? (Is the \"second\" element in the first column and second row, or is it in the first row and second column?)"
"#### 4.3 \n",
"Use an array comprehension to create an an array that stores the squares of all integers between 1 and 100."
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions 5. Conditionals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
"source": [
"### Exercises\n",
"\n",
"5.1 Rewrite the FizzBuzz test without using the `elseif` keyword."
"#### 5.1 \n",
"Write a conditional statement that prints a number if the number is even."
]
},
{
Expand All @@ -187,7 +188,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"5.2 Rewrite the FizzBuzz test using ternary operators."
"#### 5.2 \n",
"Rewrite the code above using a ternary operator."
]
},
{
Expand Down
Loading