How do i use Pycalc

Created by Stefano Palazzo
Keywords:
basic arithmetic generator
Last updated by:
Stefano Palazzo

Basic arithmetic can just be typed in naturally.

Here are some basic operators:
1+1 Addition
1-1 Subtraction
1*1 Multiplication
1/1 Division
1**1 Exponentiation
1%1 Modulo

Obviously you can use parentheses and combine multiple operations in an expression:
1.418e+12 / 2**(1/2)

Numbers can be expressed in different ways:

 - 1e21 (meaning 1 × 10²¹)
 - 0b0100 (meaning 4)
 - 0xFFF (meaning 4095)
 - 0777 (meaning 511)
 - 12+4j (a complex number)

You can covert numbers:
hex(12), bin(12), oct(12), int(12), float(12) and so on

Combine those to make calculations like this:
hex(174>>0b1)

Some more advanced operators:
1//1 Integer Division
1&1 BItwise AND
1|1 Bitwise XOR
1^1 BITWISE XOR
1<<1 Shift Left
1>>1 Shift Right
~1 Complement

Comparisons:
1==1 Equal
1!=1 Not Equal
1>=1 Greather than or Equal
1<=1 Less than or Equal

Using different Types:
You have access to various types of data. Here is an example that makes use of Booleans:
9%2==0
returns False, meaning 9 divided by two leaves a remainder – which means it's not an even number.

There are also list and set types.
A list is an unsorted collection of items.
[1,2,3,4]
a set can be created from a list:
set([1,2,3,4])
sets can be converted to lists,
list(set([1,2,3,4]))

set operators:

<= subset
< true subset
>= superset
> true superset
| union
& intersection
- difference
^ symmetric difference

and lists can be generated with 'generators'.

Generator Expression:

range(10) returns a list of 10 items
range(20,24) returns [20, 21, 22, 23]

generator expressions look like this:
(n**2 for n in range(10)) which means n squared for every n in the range of 10
and can be converted to lists
list((n**2 for n in range(10)))
or sets
set(list((n**2 for n in range(10))))

Built in functions:
There is a plethora of built in functions.
Here are just some examples:

sqrt(2)
sin(0.45)
atan(0.2)
max([1,2,3,4])

This is an expression i really like:

list(itertools.combinations([1,2,3,4],2))

prints every possible combination of two of the list [1,2,3,4]
[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]

also,
list(itertools.permutations("hello"))
might come in handy some day

There are two built in constants, pi and e.

Working with variables:
Save a variable using the setvar() method.

setvar('my_first_integer', 1)

(where 1 can be any expression)

and retrieve them using getvar()

getvar('my_first_integer')

If you want to learn more,
check out pythons documentation on math and cmath.

Pycalc can calculate anything that can be a python expression.
Have look at http://docs.python.org/ if this document didn't solve your problem (no pun intended)

Libraries that are accessible also include random, decimal, fractions, itertools and operator.

Let me know about your work and how pycalc can be made to better suit it.