so I am having issues trying to do basic math in Python. I can do basic math, but when I add in exponents, square roots, etc, I have errors with the IDE. How do I do this?
Here are a few of my problems that I am having issues with:
(n(n-1))/2)
(4)* pi * r ** 2=
(r(cos(a)**2) + r(sin(b))**2)**(.5)
((y**2) - (y**1))/((x**2) - (x**1))=
You can use
math.pow()
or the simpler**
syntax:There are two ways to complete basic maths equations in python either:
use the
**
syntax. e.g:or use
math.pow()
. e.g:As you can see, with both of these
functions
you can use anyreal
power sonegative
forinverse
ordecimals
forroots
.In general, for these types of equations, you want to look into the
math
module. It has lost of useful functions and defined constants that you may find useful. In particular for your specific problems:math.pi
and these trig. functions.I hope these examples and the links I made are useful for you :)