Commit 763b6129 by 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
 ... ... @@ -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
 \relax \providecommand\zref@newlabel[2]{}
This diff is collapsed.
This diff is collapsed.

207 KB

87.9 KB

28.7 KB

21 KB

15.1 KB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!