Python Learning Series · @onlysamarrr · Day 4 / 30

Day 4: Arithmetic Operators

Day 4 covers arithmetic operators: + adds, - subtracts, * multiplies, / divides and always gives a float, // gives the floor of the division, % gives the remainder, and ** gives a power.

Phase: Beginner · Reels: 16/450 – 20/450

Quick Answer

Day 4 covers arithmetic operators: + adds, - subtracts, * multiplies, / divides and always gives a float, // gives the floor of the division, % gives the remainder, and ** gives a power.

What You Will Learn

Code

print(7 + 2)
print(7 - 2)
print(7 * 2)
print(7 / 2)
print(7 // 2)
print(7 % 2)
print(2 ** 10)
print(-7 // 2)

Output

9
5
14
3.5
3
1
1024
-4

Code Explained, Line by Line

  1. 7 / 2 is 3.5. The / operator always returns a float, even when the answer is whole.
  2. 7 // 2 is 3. // is floor division: it rounds down to the nearest whole number.
  3. 7 % 2 is 1. % gives the remainder, which is how you test even vs odd.
  4. 2 ** 10 is 1024. ** raises a number to a power.
  5. -7 // 2 is -4, because floor division rounds down, not towards zero.
Common Mistake: Do not confuse / and //: 10 / 2 is 5.0 (a float) while 10 // 2 is 5 (an int).

Real-Life Use

Billing apps use // and % to split a bill, find change, and check whether a number is even or odd.

Practice Task: Check whether a number is even or odd using %, then write a program that splits a bill between 4 people.

Test Yourself — MCQs

Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.

Q1. What is 7 // 2?

Q2. What is 7 % 2?

Q3. What is 7 / 2?

Today's 5 Reels (from the 90-Day Plan Excel)

16/450Concept+ - * / basics
17/450Live demo// aur % ka magic
18/450Common mistake/ vs // confusion
19/450QuizQuiz: even ya odd
20/450Interview / real lifeReal life: bill split calculator
← Day 3Day 5 →