Commit b1dd943d authored by Toby Hodges's avatar Toby Hodges

updated debugging execise to be a little more descriptive

parent b1cf165f
......@@ -1022,11 +1022,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 indicated 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/is supposed to do, and correct any mistakes you encounter. Finally run the code and check that the output is the same as that indicated below.\n",
"\n",
"__Description:__\n",
"\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",
"The function `max_of_two` takes a list of tuples, with each member tuple 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, the code should print formatted strings containing the high and low values collected. \n",
"\n",
"Output expected:\n",
"\n",
......@@ -1039,34 +1039,36 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": false
},
"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",
" \n",
" # define dict with assessment values\n",
" assessment_vals = { 'Low': {}, 'High'; []}\n",
" assessment_values = { '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",
" b = item[1]\n",
" if a<b:\n",
" if a not in assessment_vals['Low']:\n",
" assessment_vals['Low'].append(a)\n",
" if b not in assessment_vals['High']:\n",
" assessment_vals['High'].append(b)\n",
" if a < b:\n",
" # add a to low and b to high (no repeats)\n",
" if a not in assessment_values['Low']:\n",
" assessment_values['Low'].append(a)\n",
" if b not in assessment_values['High']:\n",
" assessment_values['High'].append(b)\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",
" # add a to high and b to low (no repeats)\n",
" if a not in assessment_values[High]:\n",
" assessment_values[High].append(a)\n",
" if b not in assessment_values['Low']:\n",
" assessment_values['Low'].append(b)\n",
" return assessment_values\n",
" \n",
"# run function on all variables \n",
"assessment_vals = max_of_two(list0)\n",
......@@ -1079,21 +1081,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"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