The blocks in this section are your pocket calculator - use them for all kinds of mathematical calculations.
This block represents a number.
Here you can add, subtract, multiply and divide numbers. Superheroes can also do power calculations with the
2^10 means 2 to the power of 10, for example.
When you combine several math operations, be aware of the order of the operations:
In the example on the left, we calculate
(1+2)*3, whereas on the right we calculate
This block gives you access to the most commonly used mathematical functions:
- square root
- absolute (makes negative numbers positive and keeps positive numbers unchanged)
- - (multiplies by -1, i.e. makes negative numbers positive and vise versa)
- ln calculates the natural logarithm of the basis e.
- log10 calculates the logarithm of the basis 10.
- e^ calculates e to the power of x
- 10^ calculates 10 to the power of x
Calculates trigonometric functions like sine or cosine. The angle is given in degrees.
This block gives you access to various mathematical constants.
Math Number Property
Gives you access to mathematical constants like pi or e.
Rounds a point number up. By default, rounds to the nearest number, but you can also force it to always round up or always round down.
Math on List
This block performs math operations on lists (of numbers):
- sum returns the sum of all items in the list
- min returns the smallest item in the list
- max returns the largest item in the list
- average returns the average of the list items (their sum divided by the number of elements)
- median returns the median of the list items.
- modes returns a list of the most common item(s) in the list
- standard deviation returns the standard deviation of the list items
- random item returns a random element from the list
Returns the remainder of dividing the two numbers.
Constrains the number to be between the specified limits (inclusive).
Example: constrain user input
This example asks the user to enter a number; the script then makes sure that the resulting number is between 0 and 100. If the user enters something bigger than 100, for example, the result will still be 100 and if the user enters a negative number, the result will be 0.
This block returns a random number in the given range. When you generate integers, the boundaries are inclusive, i.e a random number from 0 to 10 can result in any of those numbers, including 0 and 10.
If you generate point numbers, the right boundary is exclusive, i.e. a floating point number between 0 and 10 can be 0 or 9.9999999 but never 10.
This block returns a random point number between 0 (inclusive) and 1 (exclusive). Effectively, this is just a more compact notation for