Commit fc2e0eaa authored by Toby Hodges's avatar Toby Hodges

Merge branch 'post_course_changes_TH_Apr2016' into 'master'

Post course changes April 2016

Small edits & fixes after course in Apr 2016

See merge request !11
parents 5824f92a a4f616a5
.ipynb_checkpoints/
.ipynb_checkpoints/*
......@@ -788,7 +788,7 @@
},
"outputs": [],
"source": [
"print s"
"print(s)"
]
},
{
......
......@@ -302,7 +302,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"So, as you will see from the output, a loop like this:"
"In Python 2, `range()` will give you a list of integers, while, in Python 3, you will get a `Range` object, which can be used to generate these integers. In either case, a loop like this:"
]
},
{
......@@ -321,7 +321,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"prints out the numbers 0 to 9 one to a line. The `range` function can provide most lists of numbers that you might need."
"prints out the numbers 0 to 9 one to a line. You can use the `range` function to produce most lists of numbers that you might need."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Note__ At first glance, it might seem inconvenient that you don't get a list as output from the `range()` function in Python 3. The reason behind this is that the `Range` object is a much faster and more efficient way of generating values that will be looped through one-at-a-time, and this is the aim of the vast majority of calls to the `range()` function. Of course, if you do actually want to create a full list of integer values in a range, in Python 3 you can pass the use of `range()` into the explicit initialisation of a list as below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"range_list = list(range(10)) # or\n",
"range_list = [range(10)]"
]
},
{
......@@ -474,14 +493,14 @@
"outputs": [],
"source": [
"for i in range(len(shopping)):\n",
" print 'I need to buy', amounts[i], shopping[i]"
" print('I need to buy', amounts[i], shopping[i])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"which is maybe a bit better. Taking this approach is ok, but it is difficult to control the formatting, particularly when you are mixing numbers and strings. Most programming languages have some function or facility for creating formatted strings and Python is no exception __[note]__."
"which is maybe a bit better. Taking this approach is ok, but it is difficult to control the formatting, particularly when you are mixing numbers and strings. Most programming languages have some function or facility for creating formatted strings and Python is no exception."
]
},
{
......@@ -535,7 +554,7 @@
"collapsed": true
},
"source": [
"The placeholders can also contain information for formatting the inserted value. For example, to control the number of level of precision on a floating point number, you can use `{:.Nf}` where `N` is the number of places that you want to display."
"The placeholders can also contain information for formatting the inserted value. For example, to control level of precision on a floating point number, you can use `{:.Nf}` where `N` is the number of decimal places that you want to display."
]
},
{
......@@ -557,7 +576,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There are a lot of other formatting options that can be controlled by these patterns in placeholders e.g. you can automatically print large numbers split with commas, or you can print text in clearly-defined columns buffered with whitespace. For a full list and explanation, you should check out the Python documentation at https://docs.python.org/2/library/string.html#format-string-syntax."
"There are a lot of other formatting options that can be controlled by these patterns in placeholders e.g. you can automatically print large numbers split with commas, or you can print text in clearly-defined columns buffered with whitespace. For a full list and explanation, you should check out the Python documentation at https://docs.python.org/3/library/string.html#format-string-syntax."
]
},
{
......@@ -706,7 +725,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can now put this into a `for` loop, with or without sorting it first. If we are not bothered about the order, then we can just loop directly over the dictionary: "
"We can now put this into a `for` loop, with or without sorting it first. If we are not bothered about the order, then we can use `for` and `in` to loop directly over the keys in the dictionary: "
]
},
{
......@@ -717,8 +736,8 @@
},
"outputs": [],
"source": [
"for item in studentNumbers:\n",
" print(item, studentNumbers[item])"
"for key in studentNumbers:\n",
" print(key, studentNumbers[key])"
]
},
{
......@@ -971,13 +990,6 @@
" return ---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you have a function that you think works, try using `math.hypot()` to check your answers. "
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -1038,7 +1050,7 @@
"def max_of_two(nmrs_list_list):\n",
" \n",
" # define dict with assessment values\n",
" assessment_vals = { 'Low': [], 'High': []}\n",
" assessment_vals = {'Low': [], 'High': []}\n",
" \n",
" # run through elements (lists) in input list and categorise elements\n",
" for item in nmrs_list_list:\n",
......
......@@ -654,7 +654,8 @@
},
"outputs": [],
"source": [
"# You start with a group of students and scores and you would like to print the name and the score of each.\n",
"# You start with a group of students and scores and you \n",
"# would like to print the name and the score of each.\n",
"# Can you spot and fix the errors?\n",
"# Hint: Each line contains at least one error/mistake\n",
"\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment