Skip to content

Commit 1e3b6c8

Browse files
committedMay 5, 2019
week6 Summary initial
1 parent 1085d53 commit 1e3b6c8

File tree

2 files changed

+401
-0
lines changed

2 files changed

+401
-0
lines changed
 

‎week6/Summary.ipynb

Lines changed: 401 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,401 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<img src=\"images/logo.png\" alt=\"לוגו של מיזם לימוד הפייתון. נחש מצויר בצבעי צהוב וכחול, הנע בין האותיות של שם הקורס: לומדים פייתון. הסלוגן המופיע מעל לשם הקורס הוא מיזם לימוד תכנות בחינם ובעברית.\">"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"# <span style=\"text-align: right; direction: rtl; float: right; clear: both;\"> תרגילים </span> "
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"## <span style=\"text-align: right; direction: rtl; float: right; clear: both;\">אין לזה צורה</span> "
22+
]
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
29+
" בתרגיל זה נממש טיפוס חדש מסוג <code dir=\"ltr\">Rectangle</code>.<br>\n",
30+
" לכל מלבן יש אורך <code dir=\"ltr\">height</code>ורוחב <code dir=\"ltr\">width</code>.<br>\n",
31+
" ממשו את המחלקה <code dir=\"ltr\">Rectangle</code>.\n",
32+
"</p>"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": []
41+
},
42+
{
43+
"cell_type": "markdown",
44+
"metadata": {},
45+
"source": [
46+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
47+
"צרו שני מלבנים שונים באורך וברוחב על ידי שימוש בבנאי</p>"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": []
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
62+
" ממשו מתודה בשם <code dir=\"ltr\">get_surface()</code> שתחזיר את שטח המלבן.<br>\n",
63+
" ממשו מתודה בשם <code dir=\"ltr\">get_perimeter()</code> שתחזיר את היקף המלבן.<br>\n",
64+
"</p>"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"metadata": {},
71+
"outputs": [],
72+
"source": [
73+
"# define a rectangle r and call r.get_surface() and r.get_perimeter() print to see results"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
81+
" ממשו מתודה בשם <code dir=\"ltr\">print_rectangle()</code> המדפיסה את המלבן עליו היא פועלת באופן הבא:<br>\n",
82+
"</p>\n",
83+
"<p style=\"text-align: left; direction: ltr; float: left; clear: both;\">\n",
84+
"<samp dir=\"ltr\">### Rectangle ###\n",
85+
"My Width: 10\n",
86+
"My Height: 10\n",
87+
"My Surface: 100\n",
88+
"My Perimeter: 40\n",
89+
"</samp>\n",
90+
"</p>\n"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"metadata": {},
96+
"source": [
97+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
98+
" ממשו מתודה בשם <code dir=\"ltr\">set_random_width()</code> המגרילה מספר שלם בין 1 ל-100 ומציבה אותו כרוחב המלבן.\n",
99+
"</p>"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"# define a rectangle r and call r.set_random_width() and print to see results"
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
116+
" ממשו מתודה בשם <code dir=\"ltr\">set_random_height()</code> המגרילה מספר שלם בין 1 ל-100 ומציבה אותו כאורך המלבן.\n",
117+
"</p>"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": [
126+
"# define a rectangle r and call r.set_random_height() and print to see results"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"metadata": {},
132+
"source": [
133+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
134+
" ממשו מתודה של המחלקה בשם <code dir=\"ltr\">filter_by_size(rectangle_list, threshold)</code> המקבלת רשימה של מלבנים ומחזירה רשימה של מלבנים שהשטח שלהם הוא לפחות <var dir=\"ltr\">threshold</var>.<br>\n",
135+
" עשו שימוש ב-<code dir=\"ltr\">filter</code>.<br>\n",
136+
" זכרו להפוך את תוצאת <code>filter</code> ל-<code>list</code>.\n",
137+
"</p>"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {},
144+
"outputs": [],
145+
"source": [
146+
"# call the method Rectangle.filter_by_size(rectangle_list, threshold)"
147+
]
148+
},
149+
{
150+
"cell_type": "markdown",
151+
"metadata": {},
152+
"source": [
153+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
154+
" ממשו מתודה של המחלקה בשם <code dir=\"ltr\">filter_by_perimeter(rectangle_list, threshold)</code> המקבלת רשימה של מלבנים ומחזירה רשימה של מלבנים שההיקף שלהם הוא לפחות <var dir=\"ltr\">threshold</var>.<br>\n",
155+
" עשו שימוש ב-<code dir=\"ltr\">list comprehension</code>\n",
156+
"</p>"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"metadata": {},
163+
"outputs": [],
164+
"source": [
165+
"# call the method Rectangle.filter_by_perimeter(rectangle_list, threshold)"
166+
]
167+
},
168+
{
169+
"cell_type": "markdown",
170+
"metadata": {},
171+
"source": [
172+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
173+
" כתבו מתודה של המחלקה בשם <code dir=\"ltr\">rand_rects()</code> המגרילה מספר בין 1 ל-50.<br>\n",
174+
" צרו כמות של מלבנים בהתאם למספר שהוגרל, ועבור כל מלבן הגרילו אורך ורוחב ע\"י שימוש במתודות המתאימות.<br>\n",
175+
" את כל הצורות הנ\"ל הכניסו לרשימה והדפיסו את כל הצורות בעלות שטח הגדול מ-900 והיקף גדול מ-30.</p>"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"metadata": {},
182+
"outputs": [],
183+
"source": [
184+
"# call the method Rectangle.rand_rects()"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {},
190+
"source": [
191+
"## <span style=\"text-align: right; direction: rtl; float: right; clear: both;\">מגדל קוביות</span> "
192+
]
193+
},
194+
{
195+
"cell_type": "markdown",
196+
"metadata": {},
197+
"source": [
198+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
199+
"בתרגיל זה נממש שלוש מחלקות: מחלקה של ריבוע, מחלקה של קוביות ומחלקה של מגדל קוביות.</p>"
200+
]
201+
},
202+
{
203+
"cell_type": "markdown",
204+
"metadata": {},
205+
"source": [
206+
"### <span style=\"text-align: right; direction: rtl; float: right; clear: both;\">ריבוע</span> "
207+
]
208+
},
209+
{
210+
"cell_type": "markdown",
211+
"metadata": {},
212+
"source": [
213+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
214+
"ממשו מחלקה של ריבוע.<br>\n",
215+
"בבנאי נעביר פרמטר של אורך המהווה את גודל הצלע של הריבוע (כידוע בריבוע כל הצלעות זהות בגודלן).<br>\n",
216+
"ממשו בנוסף מתודות של שטח והיקף כפי שעשיתם בתרגיל הקודם.</p>"
217+
]
218+
},
219+
{
220+
"cell_type": "code",
221+
"execution_count": null,
222+
"metadata": {},
223+
"outputs": [],
224+
"source": []
225+
},
226+
{
227+
"cell_type": "markdown",
228+
"metadata": {},
229+
"source": [
230+
"### <span style=\"text-align: right; direction: rtl; float: right; clear: both;\">קוביה</span> "
231+
]
232+
},
233+
{
234+
"cell_type": "markdown",
235+
"metadata": {},
236+
"source": [
237+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
238+
"לקוביה יש בסיס (base) שהוא קוביה וצבע (color) שהוא צבע הקוביה, הצבע נבחר מתוך: <code dir=\"ltr\">['black', 'white']</code>.<br>\n",
239+
"ממשו מחלקה ובה שתי תכונות אלו לקוביה. כמו כן ממשו מתודות המחזירות את נפח (volume) ושטח המעטפת (surface) של הקוביה.</p>"
240+
]
241+
},
242+
{
243+
"cell_type": "code",
244+
"execution_count": null,
245+
"metadata": {},
246+
"outputs": [],
247+
"source": []
248+
},
249+
{
250+
"cell_type": "markdown",
251+
"metadata": {},
252+
"source": [
253+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
254+
"כתבו מתודה המדפיסה את הקוביה באופן הבא:\n",
255+
"</p>\n",
256+
"<p style=\"text-align: left; direction: ltr; float: left; clear: both;\">\n",
257+
"<samp>Cube: base-10x10 color:black</samp>\n",
258+
"</p>"
259+
]
260+
},
261+
{
262+
"cell_type": "code",
263+
"execution_count": null,
264+
"metadata": {},
265+
"outputs": [],
266+
"source": []
267+
},
268+
{
269+
"cell_type": "markdown",
270+
"metadata": {},
271+
"source": [
272+
"### <span style=\"text-align: right; direction: rtl; float: right; clear: both;\">מגדל הקוביות</span> "
273+
]
274+
},
275+
{
276+
"cell_type": "markdown",
277+
"metadata": {},
278+
"source": [
279+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
280+
"מגדל הקוביות שלנו מכיל רשימה של קוביות המשתתפות במגדל. תמיד נתחיל ממגדל קוביות ריק.<br>\n",
281+
"קוביה יכולה להיות מעל קוביה אחרת רק אם הקוביה התחתונה היא בעלת בסיס עם צלע גדולה יותר ובעלת צבע שונה.<br>\n",
282+
"כתבו תחילה את המחלקה ואת הבנאי.</p>"
283+
]
284+
},
285+
{
286+
"cell_type": "code",
287+
"execution_count": null,
288+
"metadata": {},
289+
"outputs": [],
290+
"source": []
291+
},
292+
{
293+
"cell_type": "markdown",
294+
"metadata": {},
295+
"source": [
296+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
297+
" כעת כתבו מתודה בשם <code dir=\"ltr\">add_cube()</code> המקבלת קוביה ומוסיפה אותה למגדל אם התנאים שהוזכרו מתקיימים, אחרת לא עושה כלום.<br>\n",
298+
"אם זו הקוביה הראשונה במגדל ניתן להוסיף אותה ללא שום תנאי.\n",
299+
"</p>\n"
300+
]
301+
},
302+
{
303+
"cell_type": "code",
304+
"execution_count": null,
305+
"metadata": {},
306+
"outputs": [],
307+
"source": []
308+
},
309+
{
310+
"cell_type": "markdown",
311+
"metadata": {},
312+
"source": [
313+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
314+
"ממשו פונקציה המדפיסה את מגדל הקוביות. הקוביה התחתונה תודפס למטה והקוביה העליונה תודפס למעלה.<br>\n",
315+
"באופן הבא:\n",
316+
"</p>\n",
317+
"<p style=\"text-align: left; direction: ltr; float: left; clear: both;\">\n",
318+
"<samp dir=\"ltr\">2-Cube: base-10x10 color:black<br>1-Cube: base-15x15 color:white</samp>\n"
319+
]
320+
},
321+
{
322+
"cell_type": "markdown",
323+
"metadata": {},
324+
"source": [
325+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
326+
" כעת כתבו מתודה בשם <code dir=\"ltr\">randomize_tower()</code> הבוחרת מספר בין 1 ל-100 ובהתאם למספר זה יוצרת כמות קוביות בעלות צלע באורך אקראי (אורך 1-100) וצבע אקראי שחור או לבן.<br>\n",
327+
" את הקוביות המוגרלות ננסה להכניס למגדל באמצעות המתודה שמימשנו.<br>\n",
328+
"</p>"
329+
]
330+
},
331+
{
332+
"cell_type": "code",
333+
"execution_count": null,
334+
"metadata": {},
335+
"outputs": [],
336+
"source": []
337+
},
338+
{
339+
"cell_type": "markdown",
340+
"metadata": {},
341+
"source": [
342+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
343+
"כעת צרו מגדל ריק, השתמשו במתודה המגרילה קוביות ומלאו את המגדל בקוביות אקראיות.<br>\n",
344+
"הדפיסו את המגדל שקיבלתם.\n",
345+
"</p>"
346+
]
347+
},
348+
{
349+
"cell_type": "code",
350+
"execution_count": null,
351+
"metadata": {},
352+
"outputs": [],
353+
"source": []
354+
},
355+
{
356+
"cell_type": "markdown",
357+
"metadata": {},
358+
"source": [
359+
"### <span style=\"text-align: right; direction: rtl; float: right; clear: both;\">~בונוס~</span> "
360+
]
361+
},
362+
{
363+
"cell_type": "markdown",
364+
"metadata": {},
365+
"source": [
366+
"<p style=\"text-align: right; direction: rtl; float: right; clear: both;\">\n",
367+
"צרו בלולאה 1000 מגדלים ומלאו אותם באמצעות המתודה המגרילה.<br>\n",
368+
" מה המגדל הכי גבוה שקיבלתם?\n",
369+
"</p>"
370+
]
371+
},
372+
{
373+
"cell_type": "code",
374+
"execution_count": null,
375+
"metadata": {},
376+
"outputs": [],
377+
"source": []
378+
}
379+
],
380+
"metadata": {
381+
"kernelspec": {
382+
"display_name": "Python 3",
383+
"language": "python",
384+
"name": "python3"
385+
},
386+
"language_info": {
387+
"codemirror_mode": {
388+
"name": "ipython",
389+
"version": 3
390+
},
391+
"file_extension": ".py",
392+
"mimetype": "text/x-python",
393+
"name": "python",
394+
"nbconvert_exporter": "python",
395+
"pygments_lexer": "ipython3",
396+
"version": "3.7.1"
397+
}
398+
},
399+
"nbformat": 4,
400+
"nbformat_minor": 2
401+
}

‎week6/images/logo.png

33.9 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.