diff --git a/week2/1_Conditions.ipynb b/week2/1_Conditions.ipynb index 0094aa4..1320c7e 100644 --- a/week2/1_Conditions.ipynb +++ b/week2/1_Conditions.ipynb @@ -192,9 +192,11 @@ "ניסוח של תנאי אמור להראות ככה:\n", "
\n", "\n", - "if התנאי שלכם, ביטוי בוליאני:\n",
- "מה שאתם רוצים לעשות (גוף התנאי)
\n",
- "\n",
+ "if\n",
+ "התנאי שלכם, ביטוי בוליאני:\n",
+ "
\n",
+ "\n",
+ "מה שאתם רוצים לעשות (גוף התנאי)
\n",
"\n", "נסביר:\n", "
\n", @@ -227,15 +229,15 @@ "outputs": [], "source": [ "user_fullname = input('Please enter your full name: ')\n", - "is_tample_open = False\n", + "is_temple_open = False\n", "\n", "if 'Cohen' in user_fullname:\n", - " print('You might enter the tample!')\n", - " is_tample_open = True\n", + " print('You may enter the temple!')\n", + " is_temple_open = True\n", "\n", "print('')\n", "print('Thank you, ' + user_fullname + '.')\n", - "print('Is the tample open?: ' + str(is_tample_open))" + "print('Is the temple open?: ' + str(is_temple_open))" ] }, { @@ -269,7 +271,7 @@ " allowed_to_enter = True\n", "\n", "if age < 18:\n", - " print('Please wait to midnight before answering the following question:')\n", + " print('Please wait until midnight before answering the following question:')\n", " answer_for_birthday_is_today = input('Is it your birthday today? [yes/no]: ')\n", " if age == 17 and answer_for_birthday_is_today == 'yes':\n", " print('Happy birthday! You are 18 now.')\n", @@ -378,7 +380,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/week2/2_Conditions_part2.ipynb b/week2/2_Conditions_part2.ipynb index a9df458..f43af9c 100644 --- a/week2/2_Conditions_part2.ipynb +++ b/week2/2_Conditions_part2.ipynb @@ -50,7 +50,7 @@ "shoes_in_my_drawer = int(input(\"How many shoes do you have in your drawer? \"))\n", "\n", "if shoes_in_my_drawer % 2 == 1:\n", - " print(\"You have odd number of shoes. Something is wrong!\")" + " print(\"You have an odd number of shoes. Something is wrong!\")" ] }, { @@ -103,9 +103,9 @@ "shoes_in_my_drawer = int(input(\"How many shoes do you have in your drawer? \"))\n", "\n", "if shoes_in_my_drawer % 2 == 1:\n", - " print(\"You have odd number of shoes. Something is wrong!\")\n", + " print(\"You have an odd number of shoes. Something is wrong!\")\n", "if shoes_in_my_drawer % 2 == 0:\n", - " print(\"You have even number of shoes. Congratulations!\")" + " print(\"You have an even number of shoes. Congratulations!\")" ] }, { @@ -138,9 +138,9 @@ "shoes_in_my_drawer = int(input(\"How many shoes do you have in your drawer? \"))\n", "\n", "if shoes_in_my_drawer % 2 == 1:\n", - " print(\"You have odd number of shoes. Something is wrong!\")\n", + " print(\"You have an odd number of shoes. Something is wrong!\")\n", "else:\n", - " print(\"You have even number of shoes. Congratulations!\")" + " print(\"You have an even number of shoes. Congratulations!\")" ] }, { @@ -184,7 +184,7 @@ "metadata": {}, "source": [ ""
]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
}
],
"metadata": {
diff --git a/week2/3_Functions.ipynb b/week2/3_Functions.ipynb
index a55b742..a277b27 100644
--- a/week2/3_Functions.ipynb
+++ b/week2/3_Functions.ipynb
@@ -173,7 +173,7 @@
"protein = int(input(\"How many protein does this product have?: \"))\n",
"\n",
"total_calories = carbohydrate * 4 + fat * 9 + protein * 4\n",
- "print(\"This product have \" + str(total_calories) + \" calories in it.\")"
+ "print(\"This product has \" + str(total_calories) + \" calories in it.\")"
]
},
{
@@ -205,7 +205,7 @@
" protein = int(input(\"How many protein does this product have?: \"))\n",
"\n",
" calories = carbohydrate * 4 + fat * 9 + protein * 4\n",
- " print(\"This product have \" + str(calories) + \" calories in it.\")"
+ " print(\"This product has \" + str(calories) + \" calories in it.\")"
]
},
{
@@ -344,7 +344,7 @@
"source": [
"def calculate_calories():\n",
" calories = carbohydrate * 4 + fat * 9 + protein * 4\n",
- " print(\"This product have \" + str(calories) + \" calories in it.\")\n",
+ " print(\"This product has \" + str(calories) + \" calories in it.\")\n",
"\n",
"\n",
"carbohydrate = int(input(\"How many carbohydrate does this product have?: \"))\n",
@@ -387,7 +387,7 @@
"source": [
"def calculate_calories(carbohydrate, fat, protein):\n",
" calories = carbohydrate * 4 + fat * 9 + protein * 4\n",
- " print(\"This product have \" + str(calories) + \" calories in it.\")"
+ " print(\"This product has \" + str(calories) + \" calories in it.\")"
]
},
{
@@ -453,7 +453,7 @@
"# פרמטרים\n",
"def calculate_calories(carbohydrate, fat, protein): # כותרת הפונקציה\n",
" calories = carbohydrate * 4 + fat * 9 + protein * 4\n",
- " print(\"This product have \" + str(calories) + \" calories in it.\")\n",
+ " print(\"This product has \" + str(calories) + \" calories in it.\")\n",
"\n",
"\n",
"product_carbohydrate = int(input(\"How many carbohydrate does this product have?: \"))\n",
@@ -614,7 +614,7 @@
"metadata": {},
"outputs": [],
"source": [
- "print(\"Calories in Hamburger: \" + str(calculate_calories(50, 17.5, 36)))\n",
+ "print(\"Calories in a Hamburger: \" + str(calculate_calories(50, 17.5, 36)))\n",
"print(\"Calories in 2 Hamburgers: \" + str(2 * calculate_calories(50, 17.5, 36)))"
]
},
@@ -636,7 +636,7 @@
"metadata": {},
"outputs": [],
"source": [
- "print(\"Calories in Hamburger: \" + str(501.5))\n",
+ "print(\"Calories in a Hamburger: \" + str(501.5))\n",
"print(\"Calories in 2 Hamburgers: \" + str(2 * 501.5))"
]
},
@@ -656,7 +656,7 @@
"outputs": [],
"source": [
"calories_in_hamburger = calculate_calories(50, 17.5, 36)\n",
- "print(\"Calories in Hamburger: \" + str(calories_in_hamburger))\n",
+ "print(\"Calories in a Hamburger: \" + str(calories_in_hamburger))\n",
"print(\"Calories in 2 Hamburgers: \" + str(2 * calories_in_hamburger))"
]
},
@@ -687,7 +687,7 @@
"product_protein = int(input(\"How many protein does this product have?: \"))\n",
"# ארגומנטים\n",
"cal = calculate_calories(product_carbohydrate, product_fat, product_protein)\n",
- "print(\"This product have \" + str(cal) + \" calories in it.\")"
+ "print(\"This product has \" + str(cal) + \" calories in it.\")"
]
},
{
@@ -1156,18 +1156,9 @@
},
{
"cell_type": "code",
- "execution_count": 23,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "How many hours did it take to finish a 5km run? 5\n",
- "You can't do it :(\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"MARATHON_DISTANCE = 42.195\n",
"\n",
diff --git a/week2/4_Lists.ipynb b/week2/4_Lists.ipynb
index d545a88..8d67591 100644
--- a/week2/4_Lists.ipynb
+++ b/week2/4_Lists.ipynb
@@ -186,7 +186,7 @@
"מה התרחש בקוד?
\n",
"התחלנו את הגדרת הרשימה באמצעות התו [
.
\n",
"מיד אחרי התו הזה דאגנו להכניס איברים לרשימה לפי הסדר הרצוי, כאשר כל איבר מופרד ממשניהו בתו פסיק (,
).
\n",
- "במקרה שלנו, כל איבר הוא מחרוזת המייצגת ראש ממשלה, והם מסודרים ברשימה לפי סדר כהונתם.
\n",
+ "במקרה שלנו, כל איבר הוא מחרוזת המייצגת ראש ממשלה, ודאגנו להכניס את ראשי הממשלה לרשימה לפי סדר כהונתם.
\n",
"שימו לב שהרשימה מכילה איבר מסוים פעמיים – מכאן שרשימה היא מבנה נתונים שתומך בחזרות.
\n",
"לסיום, נסגור את הגדרת הרשימה באמצעות התו ]
.
\n",
"
\n",
- " המספור של התא הראשון הוא 0, ולא 1. יש לכך סיבות טובות, אבל פעמים רבות זה ירגיש לא טבעי ועלול ליצור באגים.
\n",
+ " המספור של התא הראשון הוא 0, ולא 1.
\n",
+ " יש לכך סיבות טובות, אבל פעמים רבות זה ירגיש לא טבעי ועלול ליצור באגים, קטעי קוד שמתנהגים אחרת משציפה המתכנת.
\n",
" כפועל יוצא, המיקום ברשימה של התא האחרון לא יהיה כאורך הרשימה, אלא כאורך הרשימה פחות אחד.
\n",
" משמע: ברשימה שבה 3 איברים, התא האחרון יהיה ממוספר 2.\n",
"
השמה ברשימות
" + "###השמה ברשימות
" ] }, { @@ -478,7 +479,8 @@ "metadata": {}, "source": [ "\n",
- "טריק שימושי בטירוף שנחמד לדעת, הוא שניתן להשתמש בהשמה על מנת לשנות את האיבר שמופיע בתא מסוים ברשימה:\n",
+ "לפעמים נרצה לשנות את הערך של האיברים ברשימה.
\n",
+ "נוכל להקביל שינוי ערך לכך שאנו נפתח את המגירה במקום ספציפי, ונחליף בין הערך הישן לחדש.\n",
"
\n",
- "כפי ש+
משרשר בין מחרוזות, הוא יודע לשרשר גם בין רשימות:\n",
+ "כפי ש־+
משרשר בין מחרוזות, הוא יודע לשרשר גם בין רשימות:\n",
"
\n",
"שימו לב שכל אופרטור שתשימו ליד הרשימה מתייחס לרשימה בלבד, ולא לאיברים שבתוכה.
\n",
"משמעו ש־+ 5
לא יוסיף לכם 5 לכל אחד מהאיברים, אלא יכשל מכיוון שפייתון לא יודע לחבר בין רשימה למספר שלם.
\n",
- "ניסיון להשתמש באופרטור *
בין רשימה למספר יגרור אותה תוצאה, ויגרום לפייתון לזרוק שגיאה.\n",
"
['Moshe', 'Splinter']
).['Moshe', 'Splinter']
.[\"Moshe\", \"Splinter\"]
.\n",
"לפעמים נרצה שהמחרוזת שלנו תעשה \"דברים מיוחדים\" – כמו לרדת שורה באמצע המחרוזת, או לעשות ריווח גדול באמצעות ↹ TAB (לצורך טבלאות, לדוגמה).
\n",
"המחשב מתייחס להזחה ולשורה חדשה כתווים של ממש, ועבור כל \"תו מיוחד\" שכזה יצרו רצף של תווים שמייצג אותו.
\n",
- "לדוגמה, כשנדע מה הוא רצף התווים שמייצגים שורה חדשה, נוכל לכתוב אותם כחלק מהמחרוזת, ובמקום בו רשמנו אותן במחרוזת נראה שורה חדשה בהדפסה.\n",
+ "לדוגמה, כשנדע מה הוא רצף התווים שמייצגים שורה חדשה, נוכל לכתוב אותם כחלק מהמחרוזת, וכאשר נדפיס אותה נראה ירידת שורה במקום רצף התווים.\n",
"
\n",
"עד כה שרשרנו מחרוזות בזהירות בעזרת סימן השרשור, +
.
\n",
- "דרך נחמדה לעשות את זה היא fstring, או בשמן המלא, formatted strings.
\n",
+ "דרך נוספת לעשות זאת היא בעזרת fstring, או בשמן המלא, formatted strings.
\n",
"נראה דוגמה:\n",
"
\n", - "שימוש ב־fstrings:\n", + "שימוש ב־fstrings:\n", "
" ] }, { "cell_type": "code", - "execution_count": 147, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "My age is 18 and my name is Yam.\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "print(f\"My age is {age} and my name is {name}.\")" ] @@ -450,7 +434,7 @@ "# נסו להכניס הרבה רווחים אחרי או לפני שם המשתמש\n", "username = input(\"Please enter your user: \")\n", "username = username.strip()\n", - "print(\"This string is: \" + username + \".\")" + "print(f\"This string is: {username}.\")" ] }, { @@ -458,7 +442,7 @@ "metadata": {}, "source": [ "\n", - " כשמביאים לה מחרוזת כארגומנט, היא תבצע את הפסאודוקוד הבא:\n", + " כאשר מעבירים לה מחרוזת כארגומנט, היא תבצע את האלגוריתם הבא:\n", "
" ] }, @@ -467,11 +451,14 @@ "metadata": {}, "source": [ "משחקים עם רישיות
" + "###משחקים עם גודלי אותיות
" ] }, { @@ -787,7 +774,7 @@ "metadata": {}, "source": [ "\n",
- "פעולה מאוד נפוצה היא replace, שעוזרת לנו להחליף תת־מחרוזת אחת באחרת.
\n",
+ "פעולה מאוד נפוצה היא replace, שעוזרת לנו להחליף את כל המופעים של תת־מחרוזת אחת באחרת.
\n",
"לדוגמה, ניקח את הברידג' השני בשיר הנפלא של הביטלס, Hey Jude, ונחליף את כל המופעים של Jude ב־Dude: \n",
"
\n", - "שימו לב לתווים המוזרים באמצע. אלו ירידות השורה, עליהם למדנו בהמשך השיעור. אל דאגה – הם לא יופיעו כשנדפיס את המחרוזת.\n", + "שימו לב לתווים המוזרים באמצע. אלו ירידות השורה, עליהם למדנו בשיעור. אל דאגה – הם לא יופיעו כשנדפיס את המחרוזת.\n", "
" ] }, @@ -1236,8 +1223,9 @@ "metadata": {}, "source": [ "\n",
- "קבלו מהמשתמש מילה מסוימת ומשפט.
\n",
- "בדקו שהמילה מופיעה לפני החצי של המשפט.\n",
+ "קבלו מהמשתמש מילה מסוימת ומשפט
\n",
+ "בדקו שהמילה מופיעה לפני החצי של המשפט.
\n",
+ "היעזרו בדוגמאות כדי לוודא את עצמכם.\n",
"