Math in python

How do I do math in gameblender python? I am well versed in VB. Do any cross reference tutorials exist to help me make this transitiion? (sorry for the newbieness of this question) :smiley:

what kind of math are you trying to do?

also, have you checked the python docs for … python?

http://www.python.org/doc/2.3.4/lib/module-math.html

Very simple…


import math

Rad = 50
X = sin(rad)
Deg = math.degrees(asin(X))

A = 5
B = 7
A+B = 12

A*B = 35
A/B = 0.71428571428571428571428571428571

And a math function:


import math

def PlayWithMyNumber(Number):
    Number=Number+5
    Number=Number-math.sin(Number)
    Number=Number*3
    Number=Number/Number
    return Number


A = 7
B=PlayWithMyNumber(A)
print B

#Output is: 1.0000000000

Anything else?

You can do a: “from math import *” instead of “import math” if you don’t like doing math.sin, math.x, etc… if you do “from math import *” than you can just do: sin(a), degrees(a), etc…

Enjoy.

And for more tuts: www.python.org
or: www.google.com

The stupid forum gives you the [ code ] [ / code ] tags so you can do things like that:

import math

def PlayWithMyNumber(Number):
        Number=Number+5
        Number=Number-math.sin(Number)
        Number=Number*3
        Number=Number/Number
        return Number

%|

Martin

The stupid forum gives you the [ code ] [ / code ] tags so you can do things like that:

import math

def PlayWithMyNumber(Number):
        Number=Number+5
        Number=Number-math.sin(Number)
        Number=Number*3
        Number=Number/Number
        return Number

%|

Martin[/quote]

%| :stuck_out_tongue: Whoops! My bad…