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
201 changes: 173 additions & 28 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,33 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here\n"
"my_list=[1,2,3,4,5,6,7,8,9,10]\n",
"new_list=[]\n",
"square=(lambda x : x**2)\n",
"\n",
"def modify_list(any_list,function):\n",
" for i in any_list:\n",
" new_list.append(function(i))\n",
" return new_list\n",
"\n",
"modify_list(my_list, square )\n",
"\n",
"\n"
]
},
{
Expand All @@ -52,11 +74,39 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 29,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[274.15,\n",
" 275.15,\n",
" 276.15,\n",
" 277.15,\n",
" 278.15,\n",
" 279.15,\n",
" 280.15,\n",
" 281.15,\n",
" 282.15,\n",
" 283.15]"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here:\n"
"\n",
"conversion_kelvin=lambda x : x+ 273.15\n",
"def temperature(any_list):\n",
" temp_list=[]\n",
" for i in any_list:\n",
" temp_list.append(conversion_kelvin(i))\n",
" return temp_list\n",
"\n",
"temperature(my_list)"
]
},
{
Expand All @@ -68,13 +118,25 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 30,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[285.15, 296.15, 311.15, 218.14999999999998, 297.15]"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"temps = [12, 23, 38, -55, 24]\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"temperature(temps)\n"
]
},
{
Expand All @@ -88,11 +150,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"# Your code here:\n",
"mod= lambda x,y : 1 if (y != 0) else 0\n",
"\n"
]
},
{
Expand All @@ -106,16 +170,31 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 36,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def divisor(a):\n",
" \"\"\"\n",
" input: a number\n",
" output: a function that returns 1 if the number is divisible by another number (to be passed later) and zero otherwise\n",
" \"\"\"\n",
" # Your code here:\n"
" x=mod(a,0)\n",
" return x\n",
"\n",
"#testing\n",
"divisor(5)\n"
]
},
{
Expand All @@ -127,11 +206,14 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"# Your code here:\n"
"expression=lambda a : 1 if (a%5==0) else 0\n",
"def divisible5(a):\n",
" return expression(a)\n",
"\n"
]
},
{
Expand All @@ -143,18 +225,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 40,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 41,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"divisible5(8)"
]
Expand Down Expand Up @@ -209,17 +313,35 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 51,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"List1 lower\n",
"List1 lower\n",
"List1 higher\n",
"List1 lower\n"
]
}
],
"source": [
"list1 = [1,2,4,4]\n",
"list2 = [2,3,3,5]\n",
"## Zip the lists together \n",
"zipped = zip(list1,list2)\n",
"\n",
"## Print the zipped list \n",
"a=list(zipped)\n",
"\n",
"## Use a lambda expression to compare if: list1 element > list2 element\n"
"## Use a lambda expression to compare if: list1 element > list2 element\n",
"\n",
"list_check=(lambda n : \"List1 higher\" if (list1[n]>list2[n]) else \"List1 lower\")\n",
"\n",
"for i in range(len(list1)):\n",
" print(list_check(i))\n"
]
},
{
Expand All @@ -242,14 +364,37 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 67,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['Lab Engineering',\n",
" 'Homework Computer Science',\n",
" 'Essay Political Science',\n",
" 'Module Mathematics']"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n",
"list2 = ['Lab', 'Homework', 'Essay', 'Module']\n",
"\n",
"# Your code here:\n"
"# Your code here:\n",
"zipl = zip(list1,list2)\n",
"\n",
"#tpp = list(map(lambda tup: ' '.join(list(tup)), zip(list1,list2)))\n",
"reversedd = list(map(lambda tup: ' '.join(tup[::-1]), zip(list1,list2)))\n",
"\n",
"reversedd\n",
"\n",
"\n",
" \n"
]
},
{
Expand Down Expand Up @@ -282,7 +427,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -296,7 +441,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down