Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 55d3977

Browse files
Add files via upload
1 parent 69a4b37 commit 55d3977

File tree

1 file changed

+362
-0
lines changed

1 file changed

+362
-0
lines changed

‎Assignment-17.ipynb‎

Lines changed: 362 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,362 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Just Right\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"guess_me = 7\n",
18+
"if guess_me < 7:\n",
19+
" print(\"Too Low\")\n",
20+
"elif guess_me == 7:\n",
21+
" print(\"Just Right\")\n",
22+
"else :\n",
23+
" print(\"Too High\")"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 5,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"too low\n",
36+
"too low\n",
37+
"too low\n",
38+
"too low\n",
39+
"too low\n",
40+
"too low\n",
41+
"found it!\n"
42+
]
43+
}
44+
],
45+
"source": [
46+
"guess_me = 7\n",
47+
"start = 1\n",
48+
"while True:\n",
49+
" if start < guess_me:\n",
50+
" print('too low')\n",
51+
" elif start == guess_me:\n",
52+
" print('found it!')\n",
53+
" break\n",
54+
" else:\n",
55+
" print('oops')\n",
56+
" break\n",
57+
" start += 1"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": 10,
63+
"metadata": {},
64+
"outputs": [
65+
{
66+
"name": "stdout",
67+
"output_type": "stream",
68+
"text": [
69+
"3\n",
70+
"2\n",
71+
"1\n",
72+
"0\n"
73+
]
74+
}
75+
],
76+
"source": [
77+
"a = [3,2,1,0]\n",
78+
"for i in a:\n",
79+
" print(i)"
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": 19,
85+
"metadata": {},
86+
"outputs": [
87+
{
88+
"data": {
89+
"text/plain": [
90+
"[0, 2, 4, 6, 8]"
91+
]
92+
},
93+
"execution_count": 19,
94+
"metadata": {},
95+
"output_type": "execute_result"
96+
}
97+
],
98+
"source": [
99+
"[i for i in range(10) if i%2==0 ]"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": 20,
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"data": {
109+
"text/plain": [
110+
"{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}"
111+
]
112+
},
113+
"execution_count": 20,
114+
"metadata": {},
115+
"output_type": "execute_result"
116+
}
117+
],
118+
"source": [
119+
"{dsq:dsq*dsq for dsq in range(10)}"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": 26,
125+
"metadata": {},
126+
"outputs": [
127+
{
128+
"data": {
129+
"text/plain": [
130+
"{1, 3, 5, 7, 9}"
131+
]
132+
},
133+
"execution_count": 26,
134+
"metadata": {},
135+
"output_type": "execute_result"
136+
}
137+
],
138+
"source": [
139+
"{sodd for sodd in range(10) if sodd%2!=0}"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": 27,
145+
"metadata": {},
146+
"outputs": [
147+
{
148+
"name": "stdout",
149+
"output_type": "stream",
150+
"text": [
151+
"Got 0\n",
152+
"Got 1\n",
153+
"Got 2\n",
154+
"Got 3\n",
155+
"Got 4\n",
156+
"Got 5\n",
157+
"Got 6\n",
158+
"Got 7\n",
159+
"Got 8\n",
160+
"Got 9\n"
161+
]
162+
}
163+
],
164+
"source": [
165+
"limit = 10\n",
166+
"string_generator = ('Got ' + str(num) for num in range(10))\n",
167+
"for item in string_generator:\n",
168+
" print(item)"
169+
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": 31,
174+
"metadata": {},
175+
"outputs": [
176+
{
177+
"data": {
178+
"text/plain": [
179+
"['Harry', 'Ron', 'Hermione']"
180+
]
181+
},
182+
"execution_count": 31,
183+
"metadata": {},
184+
"output_type": "execute_result"
185+
}
186+
],
187+
"source": [
188+
"def good():\n",
189+
" a = ['Harry','Ron','Hermione']\n",
190+
" return a\n",
191+
"good()"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": 49,
197+
"metadata": {},
198+
"outputs": [],
199+
"source": [
200+
"def get_odds():\n",
201+
" count = 0\n",
202+
" odd = (num for num in range(10) if num%2!=0 )\n",
203+
" for t in odd:\n",
204+
" if count == 2:\n",
205+
" return t\n",
206+
" break\n",
207+
" count+=1 "
208+
]
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": 50,
213+
"metadata": {},
214+
"outputs": [
215+
{
216+
"data": {
217+
"text/plain": [
218+
"5"
219+
]
220+
},
221+
"execution_count": 50,
222+
"metadata": {},
223+
"output_type": "execute_result"
224+
}
225+
],
226+
"source": [
227+
"get_odds()"
228+
]
229+
},
230+
{
231+
"cell_type": "code",
232+
"execution_count": 92,
233+
"metadata": {},
234+
"outputs": [],
235+
"source": [
236+
"import functools as fs\n",
237+
"def test_decorator(func):\n",
238+
" @fs.wraps(func)\n",
239+
" def wrapper_function():\n",
240+
" print(\"Start\")\n",
241+
" func()\n",
242+
" print(\"End\")\n",
243+
" return wrapper_function"
244+
]
245+
},
246+
{
247+
"cell_type": "code",
248+
"execution_count": 93,
249+
"metadata": {},
250+
"outputs": [],
251+
"source": [
252+
"@test_decorator\n",
253+
"def akbo():\n",
254+
" print(\"Main Function\")\n",
255+
" "
256+
]
257+
},
258+
{
259+
"cell_type": "code",
260+
"execution_count": 95,
261+
"metadata": {},
262+
"outputs": [
263+
{
264+
"name": "stdout",
265+
"output_type": "stream",
266+
"text": [
267+
"Start\n",
268+
"Main Function\n",
269+
"End\n"
270+
]
271+
}
272+
],
273+
"source": [
274+
"akbo()"
275+
]
276+
},
277+
{
278+
"cell_type": "code",
279+
"execution_count": 120,
280+
"metadata": {},
281+
"outputs": [],
282+
"source": [
283+
"class OopsException(Exception):\n",
284+
" pass"
285+
]
286+
},
287+
{
288+
"cell_type": "code",
289+
"execution_count": 121,
290+
"metadata": {},
291+
"outputs": [],
292+
"source": [
293+
"def check_number_is_5(num):\n",
294+
" if num == 5 :\n",
295+
" raise OopsException(num)"
296+
]
297+
},
298+
{
299+
"cell_type": "code",
300+
"execution_count": 122,
301+
"metadata": {},
302+
"outputs": [
303+
{
304+
"name": "stdout",
305+
"output_type": "stream",
306+
"text": [
307+
"Caught an oops\n"
308+
]
309+
}
310+
],
311+
"source": [
312+
"try:\n",
313+
" check_number_is_5(5)\n",
314+
"except OopsException:\n",
315+
" print('Caught an oops')"
316+
]
317+
},
318+
{
319+
"cell_type": "code",
320+
"execution_count": 123,
321+
"metadata": {},
322+
"outputs": [
323+
{
324+
"name": "stdout",
325+
"output_type": "stream",
326+
"text": [
327+
"{'Creature of Habit': 'A nun turns into a monster', 'Crewel Fate': 'A haunted yarn shop'}\n"
328+
]
329+
}
330+
],
331+
"source": [
332+
"titles = ['Creature of Habit', 'Crewel Fate']\n",
333+
"plots = ['A nun turns into a monster', 'A haunted yarn shop']\n",
334+
"movies = {}\n",
335+
"for title, plot in zip(titles, plots):\n",
336+
" movies[title] = plot\n",
337+
"print(movies)"
338+
]
339+
}
340+
],
341+
"metadata": {
342+
"kernelspec": {
343+
"display_name": "Python 3",
344+
"language": "python",
345+
"name": "python3"
346+
},
347+
"language_info": {
348+
"codemirror_mode": {
349+
"name": "ipython",
350+
"version": 3
351+
},
352+
"file_extension": ".py",
353+
"mimetype": "text/x-python",
354+
"name": "python",
355+
"nbconvert_exporter": "python",
356+
"pygments_lexer": "ipython3",
357+
"version": "3.8.5"
358+
}
359+
},
360+
"nbformat": 4,
361+
"nbformat_minor": 4
362+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /