Skip to the content.

Day 2: Arithmetic Operations

Learn the fundamental arithmetic operations in Python.

Task

Use arithmetic operations in Python.

Description

Python provides several arithmetic operators for mathematical calculations:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Exponentiation (**)
  • Modulus (%)
  • Floor Division (//)

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Declare two variables
a = 10
b = 5

# Perform arithmetic operations
sum_result = a + b            # Addition
difference_result = a - b     # Subtraction
product_result = a * b        # Multiplication
division_result = a / b       # Division
exponent_result = a ** b      # Exponentiation
modulus_result = a % b        # Modulus
floor_division_result = a // b # Floor Division

# Print the results
print("Sum:", sum_result)                   # Output: Sum: 15
print("Difference:", difference_result)     # Output: Difference: 5
print("Product:", product_result)           # Output: Product: 50
print("Division:", division_result)         # Output: Division: 2.0
print("Exponent:", exponent_result)         # Output: Exponent: 100000
print("Modulus:", modulus_result)           # Output: Modulus: 0
print("Floor Division:", floor_division_result) # Output: Floor Division: 2