Python

The version of Python available on your NumWorks calculator is MicroPython 1.9.4, compatible with Python 3.4.

Scripts

The script list

When you enter the application, you will see the list of saved scripts. When you first use the application, three scripts are defined as examples: factorial.py, mandelbrot.py and polynomial.py.

Adding and removing a script from the list

You can add up to 8 scripts in the list.

  1. Select the Add a script cell at the bottom of the list.
  2. Confirm by pressing ok.

A new script appears in the list. You can then enter a name for this script.

To delete a script, select the settings icon next to the script name and press ok. Choose Delete script and press ok.

Renaming a script

To change a script name, select the settings icon next to the script name and press ok. Choose Rename script and press ok to confirm. You can now change the name of the script.

Editing a script

To write to a script, simply select the script name and press ok. The editor opens and you can write your algorithms inside.

To help you write, press toolbox. A menu will open and show some shortcuts to make the editing easier. The menu Loops and Tests offers pre-filled blocks for for and while loops, if tests and a series of conditions. The menu Catalog lists the functions present in Python and gives a short description of them. You can also use the var key to display the list of functions defined in your scripts as well as the global variables.

Disabling automatic import into the shell

Automatic import is automatically enabled for your scripts. This means that the command from script_name import * is systematically entered when the shell is opened so that you can use the functions you defined in the scripts inside the console.

To disable automatic import of a script, select the settings icon next to the script name and press ok. Choose Auto import in shell and press ok to toggle the switch. The switch turns grey and the script will no longer be activated automatically.

The shell

At the bottom of the list of scripts is a button Python shell which allows access to the interactive shell of Python.

The triple arrows >>> prompts you to enter a command.

You can use the shortcuts on the toolbox menu to make text entry easier. You will also find in the menu of the var key the list of functions you have defined in your scripts.

Modules

The modules present in this version of Python are the math, cmath, random, turtle and kandinsky modules.

The math module

Here is the complete description of the math module. You can get this list on your calculator by pressing toolbox and going to Modules then math.

e

The constant e=2.718281828459045.

pi

The constant pi=3.141592653589793.

sqrt(x)

Square root, type sqrt(x) for x\sqrt{x}.

pow(x,y)

Power, type pow(x,y) for xyx^y.

exp(x)

Exponential, type exp(x) for exe^x.

expm1(x)

Exponential minus 1, type expm1(x) for ex1e^x-1.

log(x)

Natural logarithm: log(x) calculates ln(x)ln(x).

log2(x)

Base-2 logarithm, type log2(x) for ln(x)ln(2)\frac{ln(x)}{ln(2)}.

log10(x)

Base-10 logarithm, type log10(x) for ln(x)ln(10)=log(x)\frac{ln(x)}{ln(10)}=log(x).

cosh(x)

Hyperbolic cosine.

sinh(x)

Hyperbolic sine.

tanh(x)

Hyperbolic tangent.

acosh(x)

Inverse hyperbolic cosine.

asinh(x)

Inverse hyperbolic sine.

atanh(x)

Inverse hyperbolic tangent.

cos(x)

Cosine in radians.

sin(x)

Sine in radians.

tan(x)

Tangent in radians.

acos(x)

Arc cosine.

asin(x)

Arc sine.

atan(x)

Arc tangent.

atan2(y,x)

Type atan2(y,x) to calculate atan(yx)atan(\frac{y}{x}).

ceil(x)

Ceiling.

copysign(x,y)

Returns xwith the sign of y, for instance copysign(3,-1)=-3.

fabs(x)

Absolute value, fabs(x) returns x\mid x\mid.

floor(x)

Floor, type floor(x) to calculate x\lfloor x \rfloor.

fmod(a,b)

fmod(a,b) returns aa modulo bb.

frexp(x)

Mantissa and exponent of x: for instance, frexp(10) returns (0.625,4) because 10=0.625×2410=0.625\times2^4.

ldexp(x,i)

Inverse of frexp(x), that is x×2ix\times2^i.

modf(x)

Fractional and integer parts, for instance modf(5.1)=(0.1,5.0).

isfinite(x)

Checks if xis finite.

isinf(x)

Checks if xis infinity.

isnan(x)

Checks if x is NaN.

trunc(x)

Returns x truncated to an integer, for instance trunc(6.7)=6.

radians(x)

Converts x from degrees to radians, for instance radians(180) returns 3.141592653589793.

degrees(x)

Converts x from radians to degrees, for instance degrees(pi) returns 180.

erf(x)  

Error function, erf(x)=2π0xet2dterf(x) = \frac{2}{\pi}\int_0^x e^{-t^2} \, \mathrm dt.

erfc(x)

Complementary error function, erfc(x)=1erf(x)erfc(x) = 1-erf(x).

gamma(x) 

Gamma function.

lgamma(x)

Log-gamma, lgamma(x)=ln(gamma(x))lgamma(x)=ln(gamma(x)).

The cmath module

Here is the complete description of the cmath module. You can get this list on your calculator by pressing toolbox and going to Modules then cmath.

e

The constant e=2.718281828459045.

pi

The constant pi=3.141592653589793.

phase(z)

Phase of z in radians, for instance phase(1j)=1.570796326794897.

polar(z)

Representation of z in polar coordinates: polar(1j) returns (1.0, 1.570796326794897).

rect(z)

Representation of z in cartesian coordinates: rect(1,pi/4) returns 0.70710+0.70710j.

exp(x)

Exponential function, for instance exp(i*pi/4) returns 0.70710+0.70710j.

log(x)

Natural logarithm, for instance log(1j) returns 1.570796326794897j.

sqrt(x)

Square root.

cos(x)

Cosine.

sin(x)

Sine.

The random module

Here is the complete description of the random module. You can get this list on your calculator by pressing toolbox and going to Modules then random.

getrandbits(k)

Returns an integer with k random bits.

seed(x)

Initialize the random number generator.

randrange(start,stop)

Returns a random number in range(start,stop).

randint(a,b)

Returns an integer in [a,b].

choice(list)

Returns a random number in the list.

random()

Returns a random floating point number in [0,1[.

uniform(a,b)

Returns a random floating point number in [a,b].

Le module turtle

Here is the complete description of the turtle module. You can get this list on your calculator by pressing toolbox and going to Modules then turtle.

forward(x)

Move forward by x pixels.

backward(x)

Move backward by x pixels.

right(a)

Turn right by a degrees.

left(a)

Turn left by a degrees.

goto(x,y)

Move to (x,y) coordinates.

setheading(a)

Set the orientation by a degrees.

circle(r)

Circle of radius r pixels.

speed(x)

Drawing speed (x between 0 and 10).

position()

Return the current (x,y) location.

heading()

Return the current heading.

pendown()

Pull the pen down.

penup()

Pull the pen up.

pensize(x)

Set the line thickness to x pixels.

isdown()

Return True if the pen is down.

reset()

Reset the drawing.

showturtle()

Show the turtle.

hideturtle()

Hide the turtle.

color('c') or color(r,g,b)

Set the pen color.

blue

Blue color.

red

Red color.

green

Green color.

yellow

Yellow color.

brown

Brown color.

black

Black color.

white

White color.

pink

Pink color.

orange

Orange color.

purple

Purple color.

grey

Grey color.

The kandinsky module

Here is the complete description of the kandinsky module. You can get this list on your calculator by pressing toolbox and going to Modules then kandinky.

color(r,g,b)

Defines the color from the values of r,g,b.

get_pixel(x,y)

Returns the pixel x,y color.

set_pixel(x,y,color)

Colors the pixel x,y of the color color.

draw_string(text,x,y)

Displays text from the pixel x,y.

Toolbox and var keys

The var key

The menu of the var key lists all the functions defined in your scripts (containing no errors) as well as the global variables.

The Toolbox key

The toolbox key menu contains four sections for the faster editing of your scripts.

Loops and tests

Contains instructions for for and while loops as well as if tests.

Modules

Contains the functions available in the math, cmath, random and kandinsky modules.

Catalog

Contains the functions that can be used in Python, especially those of the modules but also functions like print() and input(). An alphabetical search with the letters of the keyboard is possible.

Functions

Contains instructions for defining a function: def function(argument): and return.