-1

I'm looking to do the following in python:

[0.12 x 1.616 x (100 x 0.019 x 40)^1/3] x 300 x 527.5

I can't work out how to raise to the power of a fraction. I want the output to be decimal.

(100 x 0.019 x 40)^1/3
Jacob Lee
  • 4,405
  • 2
  • 16
  • 37
nic_s
  • 3
  • 3
  • Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). Stack Overflow is not intended to replace existing documentation and tutorials. – Prune Apr 21 '21 at 22:54
  • Does this answer your question? [How do I do exponentiation in python?](https://stackoverflow.com/questions/30148740/how-do-i-do-exponentiation-in-python) – sahasrara62 Apr 21 '21 at 22:54
  • exponentiation is "**"; you used bitwise XOR. You also need to learn operator precedence: Exponentiation is always higher than division, so you have to put the division in parentheses. – Prune Apr 21 '21 at 22:55

2 Answers2

0

To raise a number n to power p, you can use the power operator **:

n ** p
TheEagle
  • 5,808
  • 3
  • 11
  • 39
0

You can use the math.pow function:

>>> import math
>>> math.pow(27, 1/3)
3.0
>>> help(math.pow)
Help on built-in function pow in module math:

pow(x, y, /)
    Return x**y (x to the power of y).

Or simply the ** (exponent) operator:

>>> 27 ** (1/3)
3.0

Also be careful of your order of operations:

>>> 27 ** 1/3  # same as: (27 ** 1) / 3
9.0
>>> 27 ** (1/3)
3.0
Woodford
  • 3,746
  • 1
  • 15
  • 29