prev next 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Computers are Good Calculators

Your computer is better than any calculator at doing math. Let's try some.


>>> print 2+33+66
101
>>> print 33333333 * 44444444
1481481451851852
>>> n=123456789
>>> print n*n*n
1881676371789154860897069
>>>  

In Python, plus and minus are normal but times and divide are done using the * and / symbol. Some other symbols to know:

+plus
-minus
*times
/divide, rounding down
x = 95save 95 as x
x == 24is x equal to 24?
x < 24is x less than 24?
x > 24is x more than 24?
len(word)the length of word
str(num)turns num into a string of digits
int(digits)makes a number from a string

What will it do when we say "len(str(1234))"?

Try your own fancy formulas. Don't worry if you get errors.