Math Examples

Example 1

Assign the variable a to 2. Assign the variable b to 3. Print the sum of the variables.

a = 2
b = 3
print(a + b)

Example 2

Assign the variable a to 2. Assign the variable b to 3. Print the difference of a and b.

a = 2
b = 3
print(a - b)

Example 3

Assign the variable a to 11 and the variable b to 7. Print the product of a and b.

a = 11
b = 7
print(a * b)

Example 4

Assign the variable a to 121 and the variable b to 11. Print the quotient of a and b.

a = 121
b = 11
print(a / b)

Example 5

Assign the variable a to 121 and the variable b to 10. Print the result of a modulus b.

a = 121
b = 10
print(a % b)

Example 6

Assign the variable a to 2 and the variable b to 6. Print the result of a raised to the power of 6.

a = 2
b = 6
print(a ^ b)

Example 7

Assign the variable a to 2 and the variable b to 2. Print the result of a raise to the power of negative b.

a = 2
b = 2
print(a ^ -b)