Commit 763b6129 authored by Karin Sasaki's avatar Karin Sasaki

added errors to last exercise or ws2 and an intro to numpy and arrays

parent 9873d798
......@@ -52,7 +52,7 @@
"source": [
"shopping = ['bread', 'potatoes', 'eggs', 'flour', 'rubber duck', 'pizza', 'milk']\n",
"for item in shopping:\n",
" print item "
" print(item)"
]
},
{
......@@ -586,7 +586,7 @@
"amounts = [‘1’, ‘10’, ‘12’, ‘1’, ‘2’, ‘5’, ‘1’]\n",
"--- i in range(len(---)):\n",
" s = 'I need to buy --- ---'.format(amounts[---], ---[i])\n",
" print ---"
" print(---)"
]
},
{
......@@ -718,7 +718,7 @@
"outputs": [],
"source": [
"for item in studentNumbers:\n",
" print item, studentNumbers[item]"
" print(item, studentNumbers[item])"
]
},
{
......@@ -773,7 +773,7 @@
"outputs": [],
"source": [
"for data in studentNumbers.items():\n",
" print data[0], data[1]"
" print(data[0], data[1])"
]
},
{
......@@ -792,7 +792,7 @@
"outputs": [],
"source": [
"for course, students in studentNumbers.items():\n",
" print course, students"
" print(course, students)"
]
},
{
......@@ -967,7 +967,7 @@
"outputs": [],
"source": [
"--- hypot(---, sideb)---\n",
" h = ---.sqrt(sidea**--- --- ---**2)\n",
" h = (sidea**--- --- ---**2)**0.5\n",
" return ---"
]
},
......@@ -1010,11 +1010,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The code below contains some typos and errors. Read the description and then follow the code, making sure you understand what each line does and correcting any mistakes you encounter. Finally run the code and check that the output is the same as that indicaded below.\n",
"The code below contains some typos and errors. Read the description and then follow the code, making sure you understand what each line does and correcting any mistakes you encounter. Finally run the code and check that the output is the same as that indicated below.\n",
"\n",
"Description:\n",
"__Description:__\n",
"\n",
"Function `max_of_two()` takes as argument a list of lists, with each member list containing two numbers each. The function allocates each number to either a 'low' or 'high' category, in a pre-defined dictionary, and returns the dictionary with the new input. There should be no repeated values in each category. Finally, using string formatting, the code prints the high and low values collected. \n",
"Function `max_of_two()` takes as its argument a list of lists, with each member list containing two numbers each. The function allocates each number to either a 'low' or 'high' category, in a pre-defined dictionary, and then returns this dictionary containing the new input. There should be no repeated values in each category. Finally, using string formatting, the code prints the high and low values collected. \n",
"\n",
"Output expected:\n",
"\n",
......@@ -1032,26 +1032,26 @@
"outputs": [],
"source": [
"# define variables to run function on\n",
"list0 = [[0.023, 0.026], [1.09,0.666], [0.346,0.953], [0.022, 0.026], [3.09,0.666], [0.336,0.943], [0.076, 0.426], [1.29,0.356], [0.146,0.953]]\n",
"list0 = [ [0.023, 0.026], [1.09,0.666] [0.346,0.953], [0.022, 0.026], [3.09,0.666], [0.336,0.943], [0.076, 0.426], [1.29,0.356], [0.146,0.953] ]\n",
"\n",
"# define function \n",
"def max_of_two(nmrs_list_list):\n",
"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",
" a = item[0]\n",
" a = item(0)\n",
" b = item[1]\n",
" if a<b:\n",
" if a not in assessment_vals['Low']:\n",
" if a not in assessment_vals['Low']:\n",
" assessment_vals['Low'].append(a)\n",
" if b not in assessment_vals['High']:\n",
" if b not in assessment_vals['High']:\n",
" assessment_vals['High'].append(b)\n",
" else:\n",
" if a not in assessment_vals['High']:\n",
" assessment_vals['High'].append(a)\n",
" else\n",
" if a not in assessment_vals[High]:\n",
" assessment_vals[High].append(a)\n",
" if b not in assessment_vals['Low']:\n",
" assessment_vals['Low'].append(b)\n",
" return assessment_vals\n",
......@@ -1060,7 +1060,7 @@
"assessment_vals = max_of_two(list0)\n",
" \n",
"# get output of code \n",
"print('The high values are {}'.format(assessment_vals['High']))\n",
"print('The high values are ()'.format(assessment_vals['High']))\n",
"print('The low values are {}'.format(assessment_vals['Low']))\n"
]
}
......
......@@ -1032,26 +1032,26 @@
"outputs": [],
"source": [
"# define variables to run function on\n",
"list0 = [[0.023, 0.026], [1.09,0.666], [0.346,0.953], [0.022, 0.026], [3.09,0.666], [0.336,0.943], [0.076, 0.426], [1.29,0.356], [0.146,0.953]]\n",
"list0 = [ [0.023, 0.026], [1.09,0.666] [0.346,0.953], [0.022, 0.026], [3.09,0.666], [0.336,0.943], [0.076, 0.426], [1.29,0.356], [0.146,0.953] ]\n",
"\n",
"# define function \n",
"def max_of_two(nmrs_list_list):\n",
"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",
" a = item[0]\n",
" a = item(0)\n",
" b = item[1]\n",
" if a<b:\n",
" if a not in assessment_vals['Low']:\n",
" if a not in assessment_vals['Low']:\n",
" assessment_vals['Low'].append(a)\n",
" if b not in assessment_vals['High']:\n",
" if b not in assessment_vals['High']:\n",
" assessment_vals['High'].append(b)\n",
" else:\n",
" if a not in assessment_vals['High']:\n",
" assessment_vals['High'].append(a)\n",
" else\n",
" if a not in assessment_vals[High]:\n",
" assessment_vals[High].append(a)\n",
" if b not in assessment_vals['Low']:\n",
" assessment_vals['Low'].append(b)\n",
" return assessment_vals\n",
......@@ -1060,28 +1060,28 @@
"assessment_vals = max_of_two(list0)\n",
" \n",
"# get output of code \n",
"print('The high values are {}'.format(assessment_vals['High']))\n",
"print('The high values are ()'.format(assessment_vals['High']))\n",
"print('The low values are {}'.format(assessment_vals['Low']))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
......
\relax
\providecommand\zref@newlabel[2]{}
This diff is collapsed.
This diff is collapsed.
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