Commit 3446440e authored by Marc Gouw's avatar Marc Gouw

Small changes and edits to Worksheet 1.

parent 28fe70e7
......@@ -34,7 +34,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"When you install Anaconda, it creates a program group containing a few different items. Included in this are the IPython Console, 'ipython-qtconsole', which you should launch and use as your Python Shell (don't worry if you don't know what a shell is at this stage!). A second item, 'spyder', is a powerful text editor with the capacity to run your Python scripts in a dedicated shell window. You should launch this and use it when you start writing multi-line code that you will want to go back and edit/append as you go through the course."
"When you install Anaconda, it creates a program group containing a few different items. Included in this an interactive python console, 'jupyter qtconsole', which you should launch and use as your Python Shell (don't worry if you don't know what a shell is at this stage!). A second item, 'spyder', is a powerful text editor with the capacity to run your Python scripts in a dedicated shell window. You should launch this and use it when you start writing multi-line code that you will want to go back and edit/append as you go through the course."
]
},
{
......@@ -50,14 +50,14 @@
"width": 50
},
"source": [
"![An example of the IPython-Qtshell window](images/IPythonQtShell.png)"
"![An example of the IPython-Qtshell window](images/JupyterConsole.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you are running Linux or Mac OS X, start a terminal, type `ipython` and press return to get the same effect within the terminal window. (To leave the shell, type `exit()` and press enter.)"
"If you are running Linux or Mac OS X, start a terminal, type `ipython` and press return to get the same program within the terminal window. (To leave the shell, type `exit()` and press enter.)"
]
},
{
......@@ -90,11 +90,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
"# type your command(s) here or use the IPython shell..."
"print('hello, world')"
]
},
{
......@@ -242,7 +242,7 @@
},
"outputs": [],
"source": [
"10 / 2 # Division"
"10 / 3 # Division"
]
},
{
......@@ -340,58 +340,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Here you should get the answer 1.4285714285714286 if you're using Python v3.x, or 1 if you're using Python 2.x. This is one of the fundamental differences between the two versions of the language. The integer result might be what you want, and maybe you will pick up the remainder with the `%` operator. However, it might also be completely wrong. It’s easy to see when this is happening if you are typing the numbers into the expressions like this, but in the next section we’ll be assigning the numbers to variables and then it can be difficult to predict whether the number a variable refers to is an integer or not (though you will see later there are ways to check this). In either version, we can force Python to give us a non-integer result like this:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"10.0 / 7"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# type your command(s) here or use the IPython shell..."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"10 / 7.0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# type your command(s) here or use the IPython shell..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Of course, you might actually only want the integer result in the first place, and regardless of the version you can force Python to give you that as well using so-called “floor division”:"
"Here you should get the answer 1.4285714285714286 if you're using Python v3.x, or 1 if you're using Python 2.x. This is because Python 2.x returns an integer value if division is done with two integers, which in this case is the result of the division ignoring any decimal values (_i.e._ \"floor division\"). This has been changed in Python 3.x., and 10/7 now gives the result you most likely expect. Of course, you might actually only want the integer result in the first place, and regardless of the version you can force Python to give you that as well using so-called “floor division”:"
]
},
{
......@@ -604,7 +553,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
......@@ -687,7 +636,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"More normally, you would probably output the results using the `print` statement we started with. In Python version 2:"
"More normally, you would probably output the results using the `print` statement we started with:"
]
},
{
......@@ -698,25 +647,14 @@
},
"outputs": [],
"source": [
"print x, y"
"print(x, y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or in version 3:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x, y)"
"If you are using Python 2.x you would use `print x, y` (without brackets), another one of the major differences between Python 2.x and Python 3.x."
]
},
{
......@@ -1296,7 +1234,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.6.0"
}
},
"nbformat": 4,
......
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