Hintor
Python Basics for Programmers

Numbers and Basic Operators

Python for Developers/Python Basics for Programmers/

Numbers and Basic Operators

Python

Lesson explanation

Numbers and Basic Operators


🎯 Learning Objective

After this lesson, you will be able to:

  • Work confidently with Python integers and floating-point values.
  • Use arithmetic operators with readable intermediate results.
  • Distinguish /, //, and % in practical calculations.
  • Apply precedence, parentheses, augmented assignment, and exponentiation correctly.

Short Explanation

Python uses integers for whole numbers and floats for decimal values. The familiar operators +, -, *, and / handle basic arithmetic. Normal division with / returns a float, even when the result is mathematically whole.

// returns the floor-divided result, while % returns the remainder. They are commonly used together for pagination, batching, time conversion, and fixed-size groups.

** means exponentiation. Augmented assignments such as += and -= update an existing value without repeating its name.

Python follows operator precedence: powers first, then multiplication and division, then addition and subtraction. Use parentheses when they make the business rule clearer or change the required order.

💡 Tip: Store meaningful intermediate values such as subtotal, remaining_seconds, or completion_rate instead of hiding an entire calculation inside one print statement.


Clean Code Examples

1. Combine basic operations

Multiplication happens before addition and subtraction.

Python
base_fee = 18
extra_users = 4
credit = 5

total = base_fee + extra_users * 3 - credit
print(total)

Output:

TEXT
25

2. Compare division, floor division, and remainder

The same values answer three different questions.

Python
records = 47
batch_size = 10

print(records / batch_size)
print(records // batch_size)
print(records % batch_size)

Output:

TEXT
4.7
4
7

3. Update a running value

Augmented assignment changes the current value in place.

Python
processed_rows = 120
processed_rows += 35
processed_rows -= 5

print(processed_rows)

Output:

TEXT
150

4. Use exponentiation

** raises the left value to the power on the right.

Python
side_length = 6
square_area = side_length ** 2

print(square_area)

Output:

TEXT
36


⚠️ Common Mistakes

  1. Do not expect / to return an integer.
  2. Do not confuse the full-group result from // with the leftover result from %.
  3. Do not use ^ for exponentiation; in Python it has a different meaning.
  4. Do not rely on remembered precedence when parentheses would make the rule clearer.
Start Practice

Python for Developers

Numbers and Basic Operators

5 tasks
Lesson progress0 / 5 tasks completed

Tasks

Practice progress

Calculate events left on the final page

View task

Complete the calculation so it prints how many events remain after all full pages.

Requirements

  • Fill only the missing operator.
  • Keep the existing values unchanged.
  • Print exactly the expected output.

Expected Output

TEXT
Events on final page: 8

Expected output

Events on final page: 8
Code: PythonTask 1

Calculate events left on the final page

Change the starter code or fill in the blanks, then run it before asking Hintor.

1
2
3
4
5

Assembled code

Preview of the code that will run

Generated code is hidden by default. Expand it only if you want to inspect what your current blank values produce.

Output / ConsolePreparing Python runtime...

0 / 5 tasks completed

Previous lessonBack to unitBack to track
GoalPython
Normal divisiona / b
Full groups or unitsa // b
Leftover amounta % b
Raise to a powera ** b
Increase an existing valuevalue += amount
Force calculation order(a + b) * c