Skip to content
Open
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
126 changes: 97 additions & 29 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.modify_list.<locals>.<lambda>(x)>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def modify_list(lst, lmbda):\n",
" \"\"\"\n",
" Input: list and lambda expression\n",
" Output: the transformed list\n",
" \"\"\"\n",
" \n",
" # your code here\n",
" "
" for item in lst: \n",
" lmbda = lambda x: x + 1\n",
" return lmbda\n",
"\n",
"modify_list([1,2,3,4,5], 2) "
]
},
{
Expand All @@ -46,11 +59,21 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"274.15\n"
]
}
],
"source": [
"# your code here"
"turn_to_kelvin = lambda x: (x + 273.15)\n",
"\n",
"print(turn_to_kelvin(1))"
]
},
{
Expand All @@ -62,13 +85,28 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]\n"
]
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# your code here"
"turn_to_kelvin = lambda x: (x + 273.15)\n",
"\n",
"turn_to_kelvin_1 = []\n",
"\n",
"for temp in temps:\n",
" turn_to_kelvin_1.append(turn_to_kelvin((temp)))\n",
"\n",
"print(turn_to_kelvin_1)"
]
},
{
Expand All @@ -82,11 +120,25 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"mod = lambda x, y: int(x % y == 0)\n",
"\n",
"\n",
"mod(100, 2)"
]
},
{
Expand All @@ -100,18 +152,12 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"def divisor(b):\n",
" \"\"\"\n",
" Input: a number\n",
" Output: a function that returns 1 if the number is \n",
" divisible by another number (to be passed later) and zero otherwise.\n",
" \"\"\"\n",
" \n",
" # your code here"
" return lambda x: mod(x, b)"
]
},
{
Expand All @@ -123,11 +169,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"divisible5 = divisor(5)"
]
},
{
Expand All @@ -139,18 +185,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
"divisible5(10)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
]
Expand Down Expand Up @@ -269,7 +337,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.9.0"
}
},
"nbformat": 4,
Expand Down