[Tutor] Squaring And Things Like That

Lloyd Hugh Allen lha2@columbia.edu
Tue, 18 Sep 2001 08:49:14 -0400


If you want to use exponents, the symbol "**" means "raised to the". So

2**3 == 8
3**2 == 9
5**5 == 625
11**2 == 121

Don't use "^". That means something completely different (as I'm sure
you've figured out).

You'll also want to "import math" and then "dir(math)" to see what other
functions are available, and you can access them by doing stuff like

math.sqrt(25)
5.

math.pi
3.1415926535897931

math.pi * 5**2
78.539816339744831

and be careful that (for your purposes) you include a decimal point any
time that you do division--otherwise python will give you the integer
part of the quotient without the remainder (for the current version of
Python). So

10/3
3

while

10./3
3.333333333333335

and you know that the last "5" is nonsense. If you want go ahead and use
integer division and recover the remainder so as to express your answer
as a mixed number, you can do

10/3
3

10%3
1

and know that the answer is three and one third (you will always use the
remainder as the numerator and the divisor as the denominator). 

Assuming that you have Python 2.1.

Good luck and stuff.

> From: "Louie Montelongo" <slim_bizkit2001@sbcglobal.net>
> To: <tutor@python.org>
> Date: Mon, 17 Sep 2001 18:36:22 -0500
> Subject: [Tutor] (no subject)
> 
> This is a multi-part message in MIME format.
> 
> ------=_NextPart_000_0005_01C13FA7.A64347C0
> Content-Type: text/plain;
>         charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> 
> I Use Python For School Work But I Don't Know How To Use It For Squaring =
> And Thngs Like That
> Please Help Me   =20
>                                                          Louie =
> Montelongo