Numbers and Math

Arithmetic Operators

OperatorDescription

Addition

+

Subtraction

-

Multiplication

*

Division

/

Power (Exponent)

^ or **

Remainder (Modulo)

%%

Negation (for Bool)

!x

Inputs:

#Assigning values to variables
n1 = 7
n2 = 3
#Testing operators
cat(n1, "+", n2, "=", n1 + n2, "\n")			# Addition
cat(n1, "-", n2, "=", n1 - n2, "\n")			# Subtraction
cat(n1, "*", n2, "=", n1 * n2, "\n")			# Multiplication
cat(n1, "/", n2, "=", n1 / n2, "\n")			# Division
cat(n1, "/", n2, "=", sprintf("%.2f", n1 / n2), "\n") 	# Print to 2 decimal places
cat(n1, "^", n2, "=", n1 ^ n2, "\n")			# Power/Exponent
cat(n1, "%%", n2, "=", n1 %% n2, "\n")		        # Remainder/Modulo

Outputs:

7 + 3 = 10 
7 - 3 = 4 
7 * 3 = 21 
7 / 3 = 2.333333 
7 / 3 = 2.33 
7 ^ 3 = 343 
7 %% 3 = 1

Logical Operators

OperatorDescription

>

Greater than

<

Less than

>=

Greater than or equal

<=

Less than or equal

==

Exactly equal

!=

Not equal to

&

Entry wise and

Resources

Last updated