Skip to content

Commit 0a68172

Browse files
Completed Assignment 22
1 parent a9fbed9 commit 0a68172

File tree

1 file changed

+375
-0
lines changed

1 file changed

+375
-0
lines changed

Assignment22.ipynb

Lines changed: 375 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,375 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "b08d7542",
6+
"metadata": {},
7+
"source": [
8+
"Create a function that takes three parameters where:\n",
9+
" x is the start of the range (inclusive).\n",
10+
" y is the end of the range (inclusive).\n",
11+
" n is the divisor to be checked against.\n",
12+
"Return an ordered list with numbers in the range that are divisible by the third parameter n.\n",
13+
"Return an empty list if there are no numbers that are divisible by n."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 6,
19+
"id": "08bf0e31",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"def list_operation(s,e,d):\n",
24+
" lst = []\n",
25+
" for i in range(s,e+1):\n",
26+
" if i%d == 0:\n",
27+
" lst.append(i)\n",
28+
" return lst"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 7,
34+
"id": "ccf7cf14",
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"data": {
39+
"text/plain": [
40+
"[3, 6, 9]"
41+
]
42+
},
43+
"execution_count": 7,
44+
"metadata": {},
45+
"output_type": "execute_result"
46+
}
47+
],
48+
"source": [
49+
"list_operation(1, 10, 3)\n"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 8,
55+
"id": "c3d6ad76",
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"data": {
60+
"text/plain": [
61+
"[8]"
62+
]
63+
},
64+
"execution_count": 8,
65+
"metadata": {},
66+
"output_type": "execute_result"
67+
}
68+
],
69+
"source": [
70+
"list_operation(7, 9, 2)"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": 9,
76+
"id": "61412ef3",
77+
"metadata": {},
78+
"outputs": [
79+
{
80+
"data": {
81+
"text/plain": [
82+
"[]"
83+
]
84+
},
85+
"execution_count": 9,
86+
"metadata": {},
87+
"output_type": "execute_result"
88+
}
89+
],
90+
"source": [
91+
"list_operation(15, 20, 7)"
92+
]
93+
},
94+
{
95+
"cell_type": "markdown",
96+
"id": "ba248ce6",
97+
"metadata": {},
98+
"source": [
99+
"A group of friends have decided to start a secret society. The name will be the first letter of\n",
100+
"each of their names, sorted in alphabetical order.\n",
101+
"Create a function that takes in a list of names and returns the name of the secret society."
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": 25,
107+
"id": "0b5eacc5",
108+
"metadata": {},
109+
"outputs": [],
110+
"source": [
111+
"def society_name(lst):\n",
112+
" s =[] \n",
113+
" lst.sort()\n",
114+
" for i in lst:\n",
115+
" s.append(i[0])\n",
116+
" x = \"\".join(s)\n",
117+
" \n",
118+
" return x"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 26,
124+
"id": "06db924d",
125+
"metadata": {},
126+
"outputs": [
127+
{
128+
"data": {
129+
"text/plain": [
130+
"'AMS'"
131+
]
132+
},
133+
"execution_count": 26,
134+
"metadata": {},
135+
"output_type": "execute_result"
136+
}
137+
],
138+
"source": [
139+
"society_name([\"Adam\",\"Sarah\",'Malcolm'])"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": 27,
145+
"id": "e50b72c9",
146+
"metadata": {},
147+
"outputs": [
148+
{
149+
"data": {
150+
"text/plain": [
151+
"'CHLN'"
152+
]
153+
},
154+
"execution_count": 27,
155+
"metadata": {},
156+
"output_type": "execute_result"
157+
}
158+
],
159+
"source": [
160+
"society_name([\"Harry\",\"Newt\",'Luna','Cho'])"
161+
]
162+
},
163+
{
164+
"cell_type": "code",
165+
"execution_count": 66,
166+
"id": "92c64223",
167+
"metadata": {},
168+
"outputs": [],
169+
"source": [
170+
"def is_isogram(s):\n",
171+
" l =s.lower()\n",
172+
" actual = len(l)\n",
173+
" q = set(l)\n",
174+
" after = len(q)\n",
175+
" if actual == after:\n",
176+
" return True\n",
177+
" else:\n",
178+
" return False\n",
179+
" "
180+
]
181+
},
182+
{
183+
"cell_type": "code",
184+
"execution_count": 67,
185+
"id": "49f65152",
186+
"metadata": {},
187+
"outputs": [
188+
{
189+
"data": {
190+
"text/plain": [
191+
"False"
192+
]
193+
},
194+
"execution_count": 67,
195+
"metadata": {},
196+
"output_type": "execute_result"
197+
}
198+
],
199+
"source": [
200+
"is_isogram(\"PasSword\")"
201+
]
202+
},
203+
{
204+
"cell_type": "code",
205+
"execution_count": 68,
206+
"id": "b51eea52",
207+
"metadata": {},
208+
"outputs": [
209+
{
210+
"data": {
211+
"text/plain": [
212+
"False"
213+
]
214+
},
215+
"execution_count": 68,
216+
"metadata": {},
217+
"output_type": "execute_result"
218+
}
219+
],
220+
"source": [
221+
"is_isogram(\"Akash\")"
222+
]
223+
},
224+
{
225+
"cell_type": "code",
226+
"execution_count": 69,
227+
"id": "3a510a11",
228+
"metadata": {},
229+
"outputs": [
230+
{
231+
"data": {
232+
"text/plain": [
233+
"True"
234+
]
235+
},
236+
"execution_count": 69,
237+
"metadata": {},
238+
"output_type": "execute_result"
239+
}
240+
],
241+
"source": [
242+
"is_isogram(\"Algorism\")"
243+
]
244+
},
245+
{
246+
"cell_type": "markdown",
247+
"id": "f8178b36",
248+
"metadata": {},
249+
"source": [
250+
"Create a function that takes a string and returns True or False, depending on whether the\n",
251+
"characters are in order or not."
252+
]
253+
},
254+
{
255+
"cell_type": "code",
256+
"execution_count": 62,
257+
"id": "fe433a03",
258+
"metadata": {},
259+
"outputs": [],
260+
"source": [
261+
"def is_in_order(s):\n",
262+
" n = len(s)\n",
263+
" for i in range(1, n):\n",
264+
" if (s[i] < s[i - 1]) :\n",
265+
" return False\n",
266+
" return True"
267+
]
268+
},
269+
{
270+
"cell_type": "code",
271+
"execution_count": 63,
272+
"id": "72bb56a7",
273+
"metadata": {},
274+
"outputs": [
275+
{
276+
"data": {
277+
"text/plain": [
278+
"True"
279+
]
280+
},
281+
"execution_count": 63,
282+
"metadata": {},
283+
"output_type": "execute_result"
284+
}
285+
],
286+
"source": [
287+
"is_in_order(\"abc\")"
288+
]
289+
},
290+
{
291+
"cell_type": "code",
292+
"execution_count": 64,
293+
"id": "d81fc22f",
294+
"metadata": {},
295+
"outputs": [
296+
{
297+
"data": {
298+
"text/plain": [
299+
"False"
300+
]
301+
},
302+
"execution_count": 64,
303+
"metadata": {},
304+
"output_type": "execute_result"
305+
}
306+
],
307+
"source": [
308+
"is_in_order(\"adc\")"
309+
]
310+
},
311+
{
312+
"cell_type": "code",
313+
"execution_count": 70,
314+
"id": "f609b7e8",
315+
"metadata": {},
316+
"outputs": [
317+
{
318+
"data": {
319+
"text/plain": [
320+
"True"
321+
]
322+
},
323+
"execution_count": 70,
324+
"metadata": {},
325+
"output_type": "execute_result"
326+
}
327+
],
328+
"source": [
329+
"is_in_order('123')"
330+
]
331+
},
332+
{
333+
"cell_type": "code",
334+
"execution_count": 71,
335+
"id": "c42d60be",
336+
"metadata": {},
337+
"outputs": [
338+
{
339+
"data": {
340+
"text/plain": [
341+
"True"
342+
]
343+
},
344+
"execution_count": 71,
345+
"metadata": {},
346+
"output_type": "execute_result"
347+
}
348+
],
349+
"source": [
350+
"is_in_order('xyzz')"
351+
]
352+
}
353+
],
354+
"metadata": {
355+
"kernelspec": {
356+
"display_name": "Python 3",
357+
"language": "python",
358+
"name": "python3"
359+
},
360+
"language_info": {
361+
"codemirror_mode": {
362+
"name": "ipython",
363+
"version": 3
364+
},
365+
"file_extension": ".py",
366+
"mimetype": "text/x-python",
367+
"name": "python",
368+
"nbconvert_exporter": "python",
369+
"pygments_lexer": "ipython3",
370+
"version": "3.7.1"
371+
}
372+
},
373+
"nbformat": 4,
374+
"nbformat_minor": 5
375+
}

0 commit comments

Comments
 (0)