Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Arithmetic Operators

Most programming languages allow you to perform arithmetic operations and mathematical calculations using arithmetic operators.

Common arithmetic operations (with Python examples) include:

NamePython SyntaxPython ExampleDescription
Addition+5 + 6Adds values
Subtraction-5 - 6Subtracts values
Multiplication*5 * 6Multiples values
Integer division//5 // 6Divides values, integers (whole numbers)
Float division/5 / 6Divides values, floating point numbers (decimal values)
Modulo%5 % 6Returns or retrieves remainder (whole number) from division operation
Exponent**5 ** 6Calculates exponent

Examples

We can run arithmetic operations directly in the console or in a script.

# sample arithmetic operation
5 + 7

But we can also assign the output of an arithmetic operation to a variable.

# sample arithmetic operation where output is assigned to variable
x = 5 + 7

# show variable value
print(x)

Python follows the PEDMAS order of operations: parenthesis, exponents, multiplication, division, addition, subtraction.

  • When in doubt, use parenthesis!

Comprehension Check

Clipboard iconArithmetic Operators Comprehension Check

Application

Q2: Write programs (or a single program) that use each of the following arithmetic operators.

  • Addition

  • Subtraction

  • Multiplication

  • Division

  • Modulus

  • Exponents

You can write separate calculations with single operators, or calculations that use multiple operators.

Answer to this question includes program + comments that document process and explain your code.

Q3: Write a program that uses arithmetic operators to convert a specific Farenheit temperature value and output its Celsius representation. Answer to this question includes program + comments that document process and explain your code.

The conversion equation is: celsius = (fahrenheit - 32.0) * 5.0 / 9.0