Skip to content

Commit e1a35e8

Browse files
committed
Add missing remove metadata
1 parent b7b8fda commit e1a35e8

File tree

2 files changed

+33
-107
lines changed

2 files changed

+33
-107
lines changed

Intermediate.ipynb

Lines changed: 20 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,7 +3746,9 @@
37463746
"cell_type": "code",
37473747
"execution_count": null,
37483748
"id": "3a8f93ee",
3749-
"metadata": {},
3749+
"metadata": {
3750+
"remove_code": "after:# Modify the function to make an empty list return 0"
3751+
},
37503752
"outputs": [],
37513753
"source": [
37523754
"def average(numbers):\n",
@@ -3755,12 +3757,7 @@
37553757
"print(average([1,2,3,4]))\n",
37563758
"print(average([]))\n",
37573759
"\n",
3758-
"# Modify the function to make an empty list return 0\n",
3759-
"def average_result(numbers):\n",
3760-
" try:\n",
3761-
" return sum(numbers) / len(numbers)\n",
3762-
" except ZeroDivisionError:\n",
3763-
" return 0"
3760+
"# Modify the function to make an empty list return 0\n"
37643761
]
37653762
},
37663763
{
@@ -3783,6 +3780,7 @@
37833780
"id": "6a7114a0",
37843781
"metadata": {
37853782
"editable": true,
3783+
"remove_code": "after:# Modify function to list the index and content of the entry that caused the error",
37863784
"slideshow": {
37873785
"slide_type": ""
37883786
},
@@ -3804,17 +3802,7 @@
38043802
"temperatures_with_error = [\"23.5\", \"25.1\", \"2020-05-21\", \"24.0\"]\n",
38053803
"print(parsed_max(temperatures_with_error))\n",
38063804
"\n",
3807-
"# Modify function to list the index and content of the entry that caused the error\n",
3808-
"def parsed_max_result(values):\n",
3809-
" max_value = None\n",
3810-
" for i, value in enumerate(values):\n",
3811-
" try:\n",
3812-
" parsed_value = float(value)\n",
3813-
" if max_value is None or parsed_value > max_value:\n",
3814-
" max_value = parsed_value\n",
3815-
" except ValueError as e:\n",
3816-
" raise ValueError(f\"Determining maximum: Could not convert '{value}' to float at index {i}\") from e\n",
3817-
" return max_value\n"
3805+
"# Modify function to list the index and content of the entry that caused the error\n"
38183806
]
38193807
},
38203808
{
@@ -3835,7 +3823,9 @@
38353823
"cell_type": "code",
38363824
"execution_count": null,
38373825
"id": "681ad2e5",
3838-
"metadata": {},
3826+
"metadata": {
3827+
"remove_code": "after:# Modify function to check for negative depth"
3828+
},
38393829
"outputs": [],
38403830
"source": [
38413831
"def water_pressure(depth_m):\n",
@@ -3847,14 +3837,7 @@
38473837
"print(water_pressure(10))\n",
38483838
"print(water_pressure(-5))\n",
38493839
"\n",
3850-
"# Modify function to check for negative depth\n",
3851-
"def water_pressure_result(depth_m):\n",
3852-
" if depth_m < 0:\n",
3853-
" raise ValueError(\"Water depth cannot be negative\")\n",
3854-
" g = 9.81 # acceleration due to gravity in m/s^2\n",
3855-
" density = 1000 # density of water in kg/m^3\n",
3856-
" pressure = density * g * depth_m\n",
3857-
" return pressure\n"
3840+
"# Modify function to check for negative depth\n"
38583841
]
38593842
},
38603843
{
@@ -3888,6 +3871,7 @@
38883871
"id": "6401f075",
38893872
"metadata": {
38903873
"editable": true,
3874+
"remove_code": "after:# Modify function to always include the timing",
38913875
"slideshow": {
38923876
"slide_type": ""
38933877
},
@@ -3915,19 +3899,9 @@
39153899
"\n",
39163900
"# Modify function to always include the timing\n",
39173901
"\n",
3918-
"def timed_calculation_result(n):\n",
3919-
" start_time = time.time()\n",
3920-
" try:\n",
39213902
" # Some complex calculation\n",
3922-
" if n < 0:\n",
3923-
" raise ValueError(\"n must be positive\")\n",
3924-
" \n",
3925-
" result = sum(i**2 for i in range(n))\n",
3926-
" return result\n",
3927-
" finally:\n",
3928-
" # Always log the execution time\n",
3929-
" elapsed = time.time() - start_time\n",
3930-
" print(f\"Calculation took {elapsed:.6f} seconds\")"
3903+
"\n",
3904+
" # Always log the execution time\n"
39313905
]
39323906
},
39333907
{
@@ -3991,7 +3965,9 @@
39913965
"cell_type": "code",
39923966
"execution_count": null,
39933967
"id": "d2151499",
3994-
"metadata": {},
3968+
"metadata": {
3969+
"remove_code": "after:# Modify the function to handle unexpected values"
3970+
},
39953971
"outputs": [],
39963972
"source": [
39973973
"def calculate_gpa(grades):\n",
@@ -4005,18 +3981,7 @@
40053981
"print(calculate_gpa([])) # Will cause ZeroDivisionError\n",
40063982
"print(calculate_gpa([3.5, \"A\", 3.7])) # Will cause TypeError\n",
40073983
"\n",
4008-
"# Modify the function to handle unexpected values\n",
4009-
"def calculate_gpa(grades):\n",
4010-
" try:\n",
4011-
" total_points = 0\n",
4012-
" for i, grade in enumerate(grades):\n",
4013-
" try:\n",
4014-
" total_points += grade\n",
4015-
" except TypeError:\n",
4016-
" raise ValueError(f\"Invalid grade '{grade}' at position {i}. Expected numeric value.\") from None\n",
4017-
" return total_points / len(grades)\n",
4018-
" except ZeroDivisionError:\n",
4019-
" return 0.0"
3984+
"# Modify the function to handle unexpected values\n"
40203985
]
40213986
},
40223987
{
@@ -4440,63 +4405,15 @@
44404405
"id": "fb0d76f6",
44414406
"metadata": {
44424407
"editable": true,
4408+
"remove_code": "all",
44434409
"slideshow": {
44444410
"slide_type": ""
44454411
},
44464412
"tags": []
44474413
},
44484414
"outputs": [],
44494415
"source": [
4450-
"import sensor_api\n",
4451-
"\n",
4452-
"class PlantSensor:\n",
4453-
" def __init__(self, sensor_id):\n",
4454-
" \"\"\"Initialize the sensor with an ID and connect to it.\"\"\"\n",
4455-
" self.sensor_id = sensor_id\n",
4456-
" self.connected = sensor_api.connect(sensor_id)\n",
4457-
" \n",
4458-
" # Store readings\n",
4459-
" self.soil_humidity = None\n",
4460-
" self.air_humidity = None\n",
4461-
" self.temperature = None\n",
4462-
" \n",
4463-
" def get_soil_humidity(self):\n",
4464-
" \"\"\"Get soil humidity reading.\"\"\"\n",
4465-
" if self.connected:\n",
4466-
" message = f\"{self.sensor_id}:SOIL_HUMIDITY\"\n",
4467-
" self.soil_humidity = float(sensor_api.send_message(message))\n",
4468-
" return self.soil_humidity\n",
4469-
" return None\n",
4470-
" \n",
4471-
" def get_air_humidity(self):\n",
4472-
" \"\"\"Get air humidity reading.\"\"\"\n",
4473-
" if self.connected:\n",
4474-
" message = f\"{self.sensor_id}:AIR_HUMIDITY\"\n",
4475-
" self.air_humidity = float(sensor_api.send_message(message))\n",
4476-
" return self.air_humidity\n",
4477-
" return None\n",
4478-
" \n",
4479-
" def get_temperature(self):\n",
4480-
" \"\"\"Get temperature reading.\"\"\"\n",
4481-
" if self.connected:\n",
4482-
" message = f\"{self.sensor_id}:TEMPERATURE\"\n",
4483-
" self.temperature = float(sensor_api.send_message(message))\n",
4484-
" return self.temperature\n",
4485-
" return None\n",
4486-
" \n",
4487-
" def display_readings(self):\n",
4488-
" \"\"\"Display all sensor readings.\"\"\"\n",
4489-
" print(f\"\\n=== Plant Sensor {self.sensor_id} Readings ===\")\n",
4490-
" print(f\"Soil Humidity: {self.soil_humidity}%\")\n",
4491-
" print(f\"Air Humidity: {self.air_humidity}%\")\n",
4492-
" print(f\"Temperature: {self.temperature}\u00b0C\")\n",
4493-
" print(\"=\" * 35)\n",
4494-
" \n",
4495-
" def disconnect(self):\n",
4496-
" \"\"\"Disconnect from the sensor.\"\"\"\n",
4497-
" if self.connected:\n",
4498-
" sensor_api.disconnect(self.sensor_id)\n",
4499-
" self.connected = False"
4416+
"\n"
45004417
]
45014418
},
45024419
{
@@ -5865,7 +5782,7 @@
58655782
],
58665783
"metadata": {
58675784
"kernelspec": {
5868-
"display_name": "Python 3 (ipykernel)",
5785+
"display_name": "teaching_data_analysis",
58695786
"language": "python",
58705787
"name": "python3"
58715788
},

Intermediate_full.ipynb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,7 +3889,9 @@
38893889
"cell_type": "code",
38903890
"execution_count": null,
38913891
"id": "3a8f93ee",
3892-
"metadata": {},
3892+
"metadata": {
3893+
"remove_code": "after:# Modify the function to make an empty list return 0"
3894+
},
38933895
"outputs": [],
38943896
"source": [
38953897
"def average(numbers):\n",
@@ -3943,6 +3945,7 @@
39433945
"id": "6a7114a0",
39443946
"metadata": {
39453947
"editable": true,
3948+
"remove_code": "after:# Modify function to list the index and content of the entry that caused the error",
39463949
"slideshow": {
39473950
"slide_type": ""
39483951
},
@@ -4012,7 +4015,9 @@
40124015
"cell_type": "code",
40134016
"execution_count": null,
40144017
"id": "681ad2e5",
4015-
"metadata": {},
4018+
"metadata": {
4019+
"remove_code": "after:# Modify function to check for negative depth"
4020+
},
40164021
"outputs": [],
40174022
"source": [
40184023
"def water_pressure(depth_m):\n",
@@ -4081,6 +4086,7 @@
40814086
"id": "6401f075",
40824087
"metadata": {
40834088
"editable": true,
4089+
"remove_code": "after:# Modify function to always include the timing",
40844090
"slideshow": {
40854091
"slide_type": ""
40864092
},
@@ -4200,7 +4206,9 @@
42004206
"cell_type": "code",
42014207
"execution_count": null,
42024208
"id": "d2151499",
4203-
"metadata": {},
4209+
"metadata": {
4210+
"remove_code": "after:# Modify the function to handle unexpected values"
4211+
},
42044212
"outputs": [],
42054213
"source": [
42064214
"def calculate_gpa(grades):\n",
@@ -4755,6 +4763,7 @@
47554763
"id": "fb0d76f6",
47564764
"metadata": {
47574765
"editable": true,
4766+
"remove_code": "all",
47584767
"slideshow": {
47594768
"slide_type": ""
47604769
},
@@ -6263,7 +6272,7 @@
62636272
],
62646273
"metadata": {
62656274
"kernelspec": {
6266-
"display_name": "Python 3 (ipykernel)",
6275+
"display_name": "teaching_data_analysis",
62676276
"language": "python",
62686277
"name": "python3"
62696278
},

0 commit comments

Comments
 (0)