Numbers & operators · מספרים ומפעילים
Two kinds of number
- An integer (
int) is a whole number, like7or-3. - A float is a number with a decimal point, like
2.5. - Division with
/always gives a float, even4 / 2→2.0.
שני סוגי מספרים
- מספר שלם (
int) הוא מספר שלם, כמו7או-3. - מספר עשרוני הוא מספר עם נקודה עשרונית, כמו
2.5. - חלוקה עם
/תמיד מחזירה מספר עשרוני, גם כאשר4 / 2→2.0.
Add, subtract, multiply, divide
+adds,-subtracts,*multiplies,/divides.- You can use them with variables or with plain numbers.
- Spaces around operators are optional but make code easier to read.
חיבור, חיסור, כפל, חלוקה
+מבצע חיבור,-חיסור,*כפל,/חלוקה.- ניתן להשתמש בהם עם משתנים או עם מספרים רגילים.
- רווחים סביב האופרטורים הם אופציונליים אך מקלים על קריאת הקוד.
print(7 + 2)
print(7 - 2)
print(7 * 2)
print(7 / 2)
Whole-number division, remainder, powers
//divides and keeps only the whole part (floor division).%gives the remainder (called modulo).**raises to a power:2 ** 3is 2×2×2.
חלוקה שלמה, שארית, חזקות
//מבצע חלוקה ומחזיר רק את החלק השלם (חלוקת רצפה).%מחזיר את השארית (נקראת also modulo).**מעלה לחזקה:2 ** 3הוא 2×2×2.
print(7 // 2)
print(7 % 2)
print(2 ** 5)
Order of operations
- Python does
**first, then*///%, then+-. - This is the same order you use in maths.
- Use parentheses
(...)to change the order.
סדר ביצועים
- Python מבצע את
**קודם, ולאחר מכן*///%, ואז+-. - זהו אותו סדר שימוש כמו במתמטיקה.
- השתמש בסוגרי parentheses
(...)כדי לשנות את הסדר.
print(2 + 3 * 4)
print((2 + 3) * 4)
Common mistakes
/always gives a float (4 / 2is2.0); use//when you want a whole number.- Power is
**, not^. "3" + "4"joins text into"34"— it does not add to7.
טעויות נפוצות
/תמיד מחזיר ערך צף (4 / 2הוא2.0); השתמש ב//כאשר אתה רוצה מספר שלם.- החזקה היא
**, לא^. "3" + "4"מאחד טקסט לתוך"34"— הוא לא מוסיף ל7.
Now you try
- Store each answer in the variable named in the task.
- Press Check answer to test your code.
כעת תנסו בעצמכם
- אחסן כל תשובה במשתנה שנקוב בשאלה.
- לחץ על בדוק תשובה כדי לבדוק את הקוד שלך.
Order of operations · סדר פעולות
Python evaluates × and ÷ before + and −, left to right. · Python מחשבת × ו-÷ לפני + ו-−, משמאל לימין.
Set length to 8 and width to 5. Then store their product in a variable called area. · הגדר את length ל-8 ואת width ל-5. לאחר מכן, אחסן את מכפלתם במשתנה בשם area.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
You share 17 sweets among 5 children. Store how many each child gets in each (use //), and how many are left over in left (use %). · אתה חלק 17 סוכריות בין 5 ילדים. אחסן כמה כל ילד מקבל ב-each (השתמש ב-//), וכמה נותרו בעודף ב-left (השתמש ב-%).
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Store 3 ** 2 + 1 in result. Then use parentheses to store (3 + 1) ** 2 in grouped. · אחסן את 3 ** 2 + 1 ב-result. לאחר מכן, השתמש בסוגריים כדי לאחסן את (3 + 1) ** 2 ב-grouped.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
celsius is 37. Store the temperature in Fahrenheit in fahrenheit, using the formula celsius × 9 ÷ 5 + 32. · celsius הוא 37. אחסן את הטמפרטורה בפרנהייט ב-fahrenheit, באמצעות הנוסחה צלנזיוס × 9 ÷ 5 + 32.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.