Skip to content
507 changes: 507 additions & 0 deletions Module01/Assignment/.ipynb_checkpoints/Assignment_01-checkpoint.ipynb

Large diffs are not rendered by default.

276 changes: 243 additions & 33 deletions Module01/Assignment/Assignment_01.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "14d461ca",
"metadata": {},
"source": [
"# In-Class Notebook: Python Review\n",
"Complete notebook in class and upload to your github repository."
]
},
{
"cell_type": "markdown",
"id": "18093846",
"metadata": {},
"source": [
" 1. Write a code that concatenates the two lists below index-wise. Create a new list that contains as it 0th index the concatenation of list1 and list2's 0th index, its 1st index as the concatenation of list1 and list2's 1st index and so on. \n",
" \n",
" Expected output:\n",
" > ['who', 'Ya', 'gonna', 'call']"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "40da6c70",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['who', 'Ya', 'gonna', 'call']\n"
]
}
],
"source": [
"list1 = ['wh','Y','gon','ca']\n",
"list2 = ['o','a','na','ll']\n",
"#solution\n",
"final=[]\n",
"for i in range(len(list1)):\n",
" w=list1[i]+list2[i]\n",
" final.append(w)\n",
"print(final)\n"
]
},
{
"cell_type": "markdown",
"id": "cde39cf8",
"metadata": {},
"source": [
"2. Write a program to iterate the first 10 numbers (0 to 9) and in each iteration, print the sum of the current and previous number.\n",
"\n",
"Expected output:\n",
"> printing current and previous number sum in a range(10)\\\n",
"> current number: 0 previous number: 0 sum: 0\\\n",
"> current number: 1 previous number: 0 sum: 1\\\n",
"> current number: 2 previous number: 1 sum: 3\\\n",
"> current number: 3 previous number: 2 sum: 5\\\n",
"> current number: 4 previous number: 3 sum: 7\\\n",
"> current number: 5 previous number: 4 sum: 9\\\n",
"> current number: 6 previous number: 5 sum: 11\\\n",
"> current number: 7 previous number: 6 sum: 13\\\n",
"> current number: 8 previous number: 7 sum: 15\\\n",
"> current number: 9 previous number: 8 sum: 17"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "0ff36244",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"current number: 0 previous number: -1 sum: -1\n",
"current number: 1 previous number: 0 sum: 1\n",
"current number: 2 previous number: 1 sum: 3\n",
"current number: 3 previous number: 2 sum: 5\n",
"current number: 4 previous number: 3 sum: 7\n",
"current number: 5 previous number: 4 sum: 9\n",
"current number: 6 previous number: 5 sum: 11\n",
"current number: 7 previous number: 6 sum: 13\n",
"current number: 8 previous number: 7 sum: 15\n",
"current number: 9 previous number: 8 sum: 17\n"
]
}
],
"source": [
"#solution\n",
"for i in range (0,10):\n",
" sum = 2*i -1\n",
" print(\"current number:\",i, \"previous number: \", i-1,\"sum:\" ,sum)"
]
},
{
"cell_type": "markdown",
"id": "8fe6e441",
"metadata": {},
"source": [
" 3. Define a function called **is_odd** that takes an integer as its argument and tells the user if it is even, odd, or zero.\n",
" \n",
" Expected Output:\n",
"> is_odd(1) \n",
">> Odd\n",
"\n",
"> is_odd(2)\n",
">> Even\n",
"\n",
"> is_odd(4)\n",
">> Even\n",
"\n",
"> is_odd(7)\n",
">> Odd\n",
"\n",
"> is_odd(0)\n",
">> integer is zero"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "2ab8aaa5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Odd\n",
"Even\n",
"Even\n",
"Odd\n",
"Integer is zero\n"
]
}
],
"source": [
"#solution\n",
"def is_odd(d):\n",
" if d == 0:\n",
" print(\"Integer is zero\")\n",
" elif d % 2 == 1:\n",
" print(\"Odd\")\n",
" else:\n",
" print(\"Even\")\n",
"\n",
"is_odd(1)\n",
"is_odd(2)\n",
"is_odd(4)\n",
"is_odd(7)\n",
"is_odd(0)"
]
},
{
"cell_type": "markdown",
"id": "bd3e504a",
"metadata": {},
"source": [
"4. Unpack the tuple tuple1.\n",
"Expected output:\n",
"> tuple1 = (0, 5, 10, 15)\\\n",
"> #Your code\\\n",
"> print(a) #should print 0\\\n",
"> print(b) #should print 5\\\n",
"> print(c) #should print 10\\\n",
"> print(d) #should print 15"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "c5da6573",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a is 0\n",
"b is 5\n",
"c is 10\n",
"d is 15\n"
]
}
],
"source": [
"tuple1 = (0, 5, 10, 15)\n",
"\n",
"#solution\n",
"a=tuple1[0]\n",
"b=tuple1[1]\n",
"c=tuple1[2]\n",
"d=tuple1[3]\n",
"print(\"a is\",a)\n",
"print(\"b is\",b)\n",
"print(\"c is\",c)\n",
"print(\"d is\",d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "098cbd19-bc95-429a-88ed-5ba31db042eb",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

Large diffs are not rendered by default.

111 changes: 98 additions & 13 deletions Module01/InClass/In-Class-Book-Python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 11,
"id": "40da6c70",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['who', 'Ya', 'gonna', 'call']\n"
]
}
],
"source": [
"list1 = ['wh','Y','gon','ca']\n",
"list2 = ['o','a','na','ll']\n",
"#solution\n"
"#solution\n",
"final=[]\n",
"for i in range(len(list1)):\n",
" w=list1[i]+list2[i]\n",
" final.append(w)\n",
"print(final)\n"
]
},
{
Expand All @@ -55,12 +68,32 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 19,
"id": "0ff36244",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"current number: 0 previous number: -1 sum: -1\n",
"current number: 1 previous number: 0 sum: 1\n",
"current number: 2 previous number: 1 sum: 3\n",
"current number: 3 previous number: 2 sum: 5\n",
"current number: 4 previous number: 3 sum: 7\n",
"current number: 5 previous number: 4 sum: 9\n",
"current number: 6 previous number: 5 sum: 11\n",
"current number: 7 previous number: 6 sum: 13\n",
"current number: 8 previous number: 7 sum: 15\n",
"current number: 9 previous number: 8 sum: 17\n"
]
}
],
"source": [
"#solution\n"
"#solution\n",
"for i in range (0,10):\n",
" sum = 2*i -1\n",
" print(\"current number:\",i, \"previous number: \", i-1,\"sum:\" ,sum)"
]
},
{
Expand Down Expand Up @@ -89,12 +122,37 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 37,
"id": "2ab8aaa5",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Odd\n",
"Even\n",
"Even\n",
"Odd\n",
"Integer is zero\n"
]
}
],
"source": [
"#solution\n"
"#solution\n",
"def is_odd(d):\n",
" if d == 0:\n",
" print(\"Integer is zero\")\n",
" elif d % 2 == 1:\n",
" print(\"Odd\")\n",
" else:\n",
" print(\"Even\")\n",
"\n",
"is_odd(1)\n",
"is_odd(2)\n",
"is_odd(4)\n",
"is_odd(7)\n",
"is_odd(0)"
]
},
{
Expand All @@ -114,15 +172,42 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 39,
"id": "c5da6573",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a is 0\n",
"b is 5\n",
"c is 10\n",
"d is 15\n"
]
}
],
"source": [
"tuple1 = (0, 5, 10, 15)\n",
"\n",
"#solution\n"
"#solution\n",
"a=tuple1[0]\n",
"b=tuple1[1]\n",
"c=tuple1[2]\n",
"d=tuple1[3]\n",
"print(\"a is\",a)\n",
"print(\"b is\",b)\n",
"print(\"c is\",c)\n",
"print(\"d is\",d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "098cbd19-bc95-429a-88ed-5ba31db042eb",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -141,7 +226,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
Loading