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
157 changes: 143 additions & 14 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"outputs": [],
"source": [
"def modify_list(lst, lmbda):\n",
" for i in lst:\n",
" return i + lmbda\n",
" \"\"\"\n",
" Input: list and lambda expression\n",
" Output: the transformed list\n",
Expand All @@ -46,11 +48,60 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"def c_to_k(c):\n",
" k=c+273.15\n",
" return k"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"275.15\n"
]
}
],
"source": [
"print(c_to_k(2))\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"lambda_c_to_k=lambda c: c + 273.15"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"275.15"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lambda_c_to_k(2)"
]
},
{
Expand All @@ -62,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -71,6 +122,32 @@
"# your code here"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"temps_c_to_k=list(map(lambda c: c + 273.15,temps))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]\n"
]
}
],
"source": [
"print(temps_c_to_k)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -82,11 +159,32 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"mod=lambda number1, number2: 1 if number1 % number2==0 else 0"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mod(4,3)"
]
},
{
Expand All @@ -100,11 +198,15 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"def divisor(b):\n",
"def divisor(b,a):\n",
" if b%a==0:\n",
" return 1\n",
" else:\n",
" return 0\n",
" \"\"\"\n",
" Input: a number\n",
" Output: a function that returns 1 if the number is \n",
Expand All @@ -123,11 +225,16 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# your code here\n",
"def divisible5(b):\n",
" if b%5==0:\n",
" return 1\n",
" else:\n",
" return 0"
]
},
{
Expand All @@ -139,18 +246,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 36,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 37,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
]
Expand Down Expand Up @@ -269,7 +398,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.8.6"
}
},
"nbformat": 4,
Expand Down