Skip to content

Commit ddb8612

Browse files
Merged PR 6: Finished exercise to close Pierian-Data#11
Finished exercise to close Pierian-Data#11 Related work items: Pierian-Data#11
2 parents 0a379e3 + 5546d6e commit ddb8612

File tree

1 file changed

+105
-61
lines changed

1 file changed

+105
-61
lines changed

03-Methods and Functions/08-Functions and Methods Homework.ipynb

+105-61
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 1,
17+
"execution_count": 5,
1818
"metadata": {},
1919
"outputs": [],
2020
"source": [
2121
"def vol(rad):\n",
22-
" pass"
22+
" return (4/3)*(3.14) * (rad ** 3)"
2323
]
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 2,
27+
"execution_count": 6,
2828
"metadata": {},
2929
"outputs": [
3030
{
3131
"data": {
32-
"text/plain": [
33-
"33.49333333333333"
34-
]
32+
"text/plain": "33.49333333333333"
3533
},
36-
"execution_count": 2,
34+
"execution_count": 6,
3735
"metadata": {},
3836
"output_type": "execute_result"
3937
}
@@ -53,32 +51,55 @@
5351
},
5452
{
5553
"cell_type": "code",
56-
"execution_count": 3,
54+
"execution_count": 25,
5755
"metadata": {},
5856
"outputs": [],
5957
"source": [
6058
"def ran_check(num,low,high):\n",
61-
" pass"
59+
" x = [r for r in range(low, high+1)]\n",
60+
" if num in x:\n",
61+
" return f'{num} is in the range between {low} and {high}'\n",
62+
" else:\n",
63+
" return f'{num} is not in the range between {low} and {high}'"
6264
]
6365
},
6466
{
6567
"cell_type": "code",
66-
"execution_count": 4,
68+
"execution_count": 26,
6769
"metadata": {},
6870
"outputs": [
6971
{
70-
"name": "stdout",
71-
"output_type": "stream",
72-
"text": [
73-
"5 is in the range between 2 and 7\n"
74-
]
72+
"data": {
73+
"text/plain": "'5 is in the range between 2 and 7'"
74+
},
75+
"execution_count": 26,
76+
"metadata": {},
77+
"output_type": "execute_result"
7578
}
7679
],
7780
"source": [
7881
"# Check\n",
7982
"ran_check(5,2,7)"
8083
]
8184
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": 24,
88+
"metadata": {},
89+
"outputs": [
90+
{
91+
"data": {
92+
"text/plain": "'5 is in the range between 2 and 7'"
93+
},
94+
"execution_count": 24,
95+
"metadata": {},
96+
"output_type": "execute_result"
97+
}
98+
],
99+
"source": [
100+
"ran_check(5,2,7)"
101+
]
102+
},
82103
{
83104
"cell_type": "markdown",
84105
"metadata": {},
@@ -88,26 +109,28 @@
88109
},
89110
{
90111
"cell_type": "code",
91-
"execution_count": 5,
112+
"execution_count": 29,
92113
"metadata": {},
93114
"outputs": [],
94115
"source": [
95116
"def ran_bool(num,low,high):\n",
96-
" pass"
117+
" x = [r for r in range(low, high+1)]\n",
118+
" if num in x:\n",
119+
" return True\n",
120+
" else:\n",
121+
" return False"
97122
]
98123
},
99124
{
100125
"cell_type": "code",
101-
"execution_count": 6,
126+
"execution_count": 30,
102127
"metadata": {},
103128
"outputs": [
104129
{
105130
"data": {
106-
"text/plain": [
107-
"True"
108-
]
131+
"text/plain": "True"
109132
},
110-
"execution_count": 6,
133+
"execution_count": 30,
111134
"metadata": {},
112135
"output_type": "execute_result"
113136
}
@@ -135,27 +158,40 @@
135158
},
136159
{
137160
"cell_type": "code",
138-
"execution_count": 7,
161+
"execution_count": 107,
139162
"metadata": {},
140163
"outputs": [],
141164
"source": [
142165
"def up_low(s):\n",
143-
" pass"
166+
" import collections\n",
167+
" from collections import Counter\n",
168+
"\n",
169+
" u = Counter()\n",
170+
" l = Counter()\n",
171+
" for letter in s:\n",
172+
" l[letter.islower()] += 1\n",
173+
" u[letter.isupper()] += 1\n",
174+
" \n",
175+
" #print(u[True], l[True])\n",
176+
" return(\n",
177+
" f\"Original String : {s}\"\n",
178+
" f\"No. of Upper case characters : {u[True]}\"\n",
179+
" f\"No. of Lower case characters : {l[True]}\"\n",
180+
" )"
144181
]
145182
},
146183
{
147184
"cell_type": "code",
148-
"execution_count": 8,
185+
"execution_count": 108,
149186
"metadata": {},
150187
"outputs": [
151188
{
152-
"name": "stdout",
153-
"output_type": "stream",
154-
"text": [
155-
"Original String : Hello Mr. Rogers, how are you this fine Tuesday?\n",
156-
"No. of Upper case characters : 4\n",
157-
"No. of Lower case Characters : 33\n"
158-
]
189+
"data": {
190+
"text/plain": "'Original String : Hello Mr. Rogers, how are you this fine Tuesday?No. of Upper case characters : 4No. of Lower case characters : 33'"
191+
},
192+
"execution_count": 108,
193+
"metadata": {},
194+
"output_type": "execute_result"
159195
}
160196
],
161197
"source": [
@@ -176,26 +212,24 @@
176212
},
177213
{
178214
"cell_type": "code",
179-
"execution_count": 9,
215+
"execution_count": 109,
180216
"metadata": {},
181217
"outputs": [],
182218
"source": [
183219
"def unique_list(lst):\n",
184-
" pass"
220+
" return set(lst)"
185221
]
186222
},
187223
{
188224
"cell_type": "code",
189-
"execution_count": 10,
225+
"execution_count": 110,
190226
"metadata": {},
191227
"outputs": [
192228
{
193229
"data": {
194-
"text/plain": [
195-
"[1, 2, 3, 4, 5]"
196-
]
230+
"text/plain": "{1, 2, 3, 4, 5}"
197231
},
198-
"execution_count": 10,
232+
"execution_count": 110,
199233
"metadata": {},
200234
"output_type": "execute_result"
201235
}
@@ -217,26 +251,27 @@
217251
},
218252
{
219253
"cell_type": "code",
220-
"execution_count": 11,
254+
"execution_count": 111,
221255
"metadata": {},
222256
"outputs": [],
223257
"source": [
224258
"def multiply(numbers): \n",
225-
" pass"
259+
" x = 1\n",
260+
" for y in numbers:\n",
261+
" x = x * y\n",
262+
" return x"
226263
]
227264
},
228265
{
229266
"cell_type": "code",
230-
"execution_count": 12,
267+
"execution_count": 112,
231268
"metadata": {},
232269
"outputs": [
233270
{
234271
"data": {
235-
"text/plain": [
236-
"-24"
237-
]
272+
"text/plain": "-24"
238273
},
239-
"execution_count": 12,
274+
"execution_count": 112,
240275
"metadata": {},
241276
"output_type": "execute_result"
242277
}
@@ -257,26 +292,31 @@
257292
},
258293
{
259294
"cell_type": "code",
260-
"execution_count": 13,
295+
"execution_count": 141,
261296
"metadata": {},
262297
"outputs": [],
263298
"source": [
264299
"def palindrome(s):\n",
265-
" pass"
300+
" x = [n for n in s]\n",
301+
" y = [n for n in s]\n",
302+
" y.reverse()\n",
303+
"\n",
304+
" if x == y:\n",
305+
" return True\n",
306+
" else:\n",
307+
" return False"
266308
]
267309
},
268310
{
269311
"cell_type": "code",
270-
"execution_count": 14,
312+
"execution_count": 143,
271313
"metadata": {},
272314
"outputs": [
273315
{
274316
"data": {
275-
"text/plain": [
276-
"True"
277-
]
317+
"text/plain": "True"
278318
},
279-
"execution_count": 14,
319+
"execution_count": 143,
280320
"metadata": {},
281321
"output_type": "execute_result"
282322
}
@@ -302,28 +342,32 @@
302342
},
303343
{
304344
"cell_type": "code",
305-
"execution_count": 15,
345+
"execution_count": 217,
306346
"metadata": {},
307347
"outputs": [],
308348
"source": [
309349
"import string\n",
310350
"\n",
311351
"def ispangram(str1, alphabet=string.ascii_lowercase):\n",
312-
" pass"
352+
" x = set([l for l in str1.lower().replace(' ','')])\n",
353+
" alphabet = set(alphabet)\n",
354+
" \n",
355+
" if x == alphabet:\n",
356+
" return True\n",
357+
" else:\n",
358+
" return False"
313359
]
314360
},
315361
{
316362
"cell_type": "code",
317-
"execution_count": 16,
363+
"execution_count": 218,
318364
"metadata": {},
319365
"outputs": [
320366
{
321367
"data": {
322-
"text/plain": [
323-
"True"
324-
]
368+
"text/plain": "True"
325369
},
326-
"execution_count": 16,
370+
"execution_count": 218,
327371
"metadata": {},
328372
"output_type": "execute_result"
329373
}
@@ -383,4 +427,4 @@
383427
},
384428
"nbformat": 4,
385429
"nbformat_minor": 1
386-
}
430+
}

0 commit comments

Comments
 (0)