انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Python: home
0. Lab tour1
1. The start5
2. Variables and input5
3. Conditions5
4. Loops5
5. Lists4
6. Functions4
7. Drawing with the turtle3
8. The project: the guess-the-number game3
9. Strings in depth1
10. Dictionaries (dict)3
11. Randomness and errors3
12. Classes and objects (class)2
13. Pro drawing and charts3
14. The final project: the quiz game2

Numbers and arithmetic

Section 2: Variables and inputLesson 2.2 · ⏱ 7 min

Adding +, taking away -, multiplying *, dividing /, and the remainder %.

apples = 17
friends = 5
print(apples / friends)
print(apples // friends)
print(apples % friends)
🖥️ The output in Robo Python:
3.4
3
2
🐍 Open the code in Robo Python ↗
The example in Robo Python: the code on the right and what appeared on the left
The example in Robo Python: the code on the right and what appeared on the left
📌 Note
// divides with no fractions: each friend gets 3 apples, and % is what's left: two apples remain.

📌 Another example: kinds of division

/ ordinary division, // with no fractions, and % the remainder.

🐍 Kinds of division
print(17 / 5)
print(17 // 5)
print(17 % 5)
print(2 ** 10)
🖥️ The output in Robo Python:
3.4
3
2
1024
🐍 Open the code in Robo Python ↗
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

The area of a rectangle 12 long and 7 wide.

👀 Show the solution
🐍 Solution
length = 12
width = 7
print(length * width)
🖥️ The output in Robo Python:
84
🐍 Open the code in Robo Python ↗

Result: 84

Medium

You have 50 sweets and 6 friends: how many does each get, and how many are left?

👀 Show the solution
🐍 Solution
sweets = 50
friends = 6
print("each:", sweets // friends)
print("left:", sweets % friends)
🖥️ The output in Robo Python:
each: 8
left: 2
🐍 Open the code in Robo Python ↗

Result: each: 8 and left: 2

Hard

How many seconds are in a day?

👀 Show the solution
🐍 Solution
print(24 * 60 * 60)
🖥️ The output in Robo Python:
86400
🐍 Open the code in Robo Python ↗

Result: 86400

Finished the lesson? Mark it so your progress counts.