Learn
Python Syntax
Arithmetic

One thing computers are capable of doing exceptionally well is performing arithmetic. Addition, subtraction, multiplication, division, and other numeric calculations are easy to do in most programming languages, and Python is no exception. Some examples:

mirthful_addition = 12381 + 91817 amazing_subtraction = 981 - 312 trippy_multiplication = 38 * 902 happy_division = 540 / 45 sassy_combinations = 129 * 1345 + 120 / 6 - 12

Above are a number of arithmetic operations, each assigned to a variable. The variable will hold the final result of each operation. Combinations of arithmetical operators follow the usual order of operations.

Python also offers a companion to division called the modulo operator. The modulo operator is indicated by % and returns the remainder after division is performed.

is_this_number_odd = 15 % 2 is_this_number_divisible_by_seven = 133 % 7

In the above code block, we use the modulo operator to find the remainder of 15 divided by 2. Since 15 is an odd number the remainder is 1.

We also check the remainder of 133 / 7. Since 133 divided by 7 has no remainder, 133 % 7 evaluates to 0.

Instructions

1.

Multiply two numbers together and assign the result to a variable called product.

2.

What is the remainder when 1398 is divided by 11? Save the results in a variable called remainder.

Folder Icon

Take this course for free

Already have an account?