Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 112 additions & 19 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,86 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# This is a function, which we will learn more about next week. For testing purposes, we will write our code in the function\n",
"def anagram_checker(word_a, word_b):\n",
" # Your code here\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\")"
"# sort letters of the two words\n",
" sorted_word_a = sorted(word_a)\n",
" sorted_word_b = sorted(word_b)\n",
" \n",
"# determine if sorted words are the same \n",
" return sorted_word_a == sorted_word_b"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"Silent\", \"Night\")"
"# compare \"Silent\" and \"listen\"\n",
"result = anagram_checker(\"Silent\", \"listen\")\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker(\"night\", \"Thing\")"
"# compare \"Silent\" and \"Night\"\n",
"result = anagram_checker(\"Silent\", \"Night\")\n",
"result"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# compare \"night\" and \"Thing\"\n",
"result = anagram_checker(\"night\", \"Thing\")\n",
"result"
]
},
{
Expand All @@ -97,24 +149,65 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def anagram_checker(word_a, word_b, is_case_sensitive):\n",
" # Modify your existing code here\n",
" # sort the words\n",
" # sorted_worda = sorted(worda)\n",
" # sorted_wordb = sorted(wordb)\n",
"\n",
" # determine if sorted words are the same\n",
" if not is_case_sensitive:\n",
" word_a = word_a.lower()\n",
" word_b = word_b.lower()\n",
"\n",
"# Run your code to check using the words below:\n",
"anagram_checker(\"Silent\", \"listen\", False) # True"
" sorted_word_a = sorted(word_a)\n",
" sorted_word_b = sorted(word_b)\n",
"\n",
" if sorted_word_a == sorted_word_b:\n",
" return True\n",
" else:\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"# Compare \"Silent\" and \"listen\" to determine if they are anagrams\n",
"anagram_checker(\"Silent\", \"listen\", False)\n",
"print(anagram_checker(\"Silent\", \"listen\", False))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"anagram_checker(\"Silent\", \"Listen\", True) # False"
"# Step 6 - Compare \"Silent\" and \"Listen\" to determine if they are anagrams \n",
"anagram_checker(\"Silent\", \"Listen\", True)\n",
"print(anagram_checker(\"Silent\", \"listen\", True))"
]
},
{
Expand Down Expand Up @@ -144,7 +237,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down
78 changes: 69 additions & 9 deletions 02_activities/assignments/assignment_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,37 @@
},
"outputs": [],
"source": [
"all_paths = [ \n",
"\"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_02.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_03.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_04.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_05.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_06.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_07.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_08.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_09.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_10.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_11.csv\",\n",
"\"../../05_src/data/assignment_2_data/inflammation_12.csv\" \n",
"]\n",
"\n",
" \n",
"with open(all_paths[0], 'r') as f:\n",
" # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into 'contents'\n",
" contents=f.readline()\n",
" print('Printing from the file, but just the first line:', contents)\n",
" \n",
" # YOUR CODE HERE: Iterate through 'contents' using a for loop and print each row for inspection"
"\n",
" # YOUR CODE HERE: Iterate through 'contents' using a for loop and print each row for inspection\n",
"\n",
" if not contents:\n",
" print(\"Contents are empty\")\n",
" else:\n",
" print('These lines are from the same file:')\n",
" contents = f.readlines()\n",
" for row in contents:\n",
" print(row) \n"
]
},
{
Expand Down Expand Up @@ -134,33 +161,62 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"a = 1\n",
"print(type(a))\n",
"b = float(a)\n",
"print(type(b))"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"id": "82-bk4CBB1w4"
},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"def patient_summary(file_path, operation):\n",
"def patient_summary(all_paths, operation):\n",
" #summary_values = np.zeros(60)\n",
" \n",
" # load the data from the file\n",
" data = np.loadtxt(fname=file_path, delimiter=',')\n",
" for idx, file_path in enumerate(all_paths):\n",
" data = np.loadtxt(fname=all_paths, delimiter=',')\n",
" ax = 1 # this specifies that the operation should be done for each row (patient)\n",
"\n",
" # implement the specific operation based on the 'operation' argument\n",
" if operation == 'mean':\n",
" # YOUR CODE HERE: calculate the mean (average) number of flare-ups for each patient\n",
" result = np.mean(data, axis=ax)\n",
"\n",
" elif operation == 'max':\n",
" # YOUR CODE HERE: calculate the maximum number of flare-ups experienced by each patient\n",
" result = np.max(data, axis=ax)\n",
"\n",
" elif operation == 'min':\n",
" # YOUR CODE HERE: calculate the minimum number of flare-ups experienced by each patient\n",
" result = np.min(data, axis=ax)\n",
"\n",
" else:\n",
" # if the operation is not one of the expected values, raise an error\n",
" raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n",
"\n",
" return summary_values"
" #summary_values[idx] = result\n",
" return result\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" mean_values = patient_summary(all_paths[0], 'mean')\n",
" print(mean_values)"
]
},
{
Expand Down Expand Up @@ -238,7 +294,7 @@
},
"outputs": [],
"source": [
"# Run this cell so you can use this helper function\n",
"# Run this cell so you can use this helper function - updated\n",
"\n",
"def check_zeros(x):\n",
" '''\n",
Expand All @@ -255,7 +311,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 53,
"metadata": {
"id": "LEYPM5v4JT0i"
},
Expand All @@ -265,8 +321,12 @@
"\n",
"def detect_problems(file_path):\n",
" #YOUR CODE HERE: use patient_summary() to get the means and check_zeros() to check for zeros in the means\n",
"\n",
" return"
" mean_scores = patient_summary(file_path, 'mean') \n",
" has_zeros = check_zeros(mean_scores)\n",
" if has_zeros:\n",
" return True\n",
" else:\n",
" return False "
]
},
{
Expand Down Expand Up @@ -331,7 +391,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.15"
}
},
"nbformat": 4,
Expand Down