-3

I am new to programming and just started a course and stuck on a demo section where I have to take a math calculation and program it in Python. When I program it do you follow BEDMAS order of figuring out or is there a logical order. The syntax is correct but I keep being told it is not right

See the equation below to be programmed into python. What are the rules for telling Python to calculate something correctly where 5 is the exponent

Use Python to calculate (((1+2)∗3)/4)5

Acorn
  • 24,970
  • 5
  • 40
  • 69
Bender
  • 1
  • 1
    Hate to be this guy, but can you not google "Python exponentiation"?? See this, for example: https://stackoverflow.com/questions/30148740/how-do-i-do-exponentiation-in-python/30149434 – ForceBru Sep 12 '20 at 20:46

2 Answers2

0

Exponentiation in Python is done with the ** operator.

For instance:

2**8

is 256.

Acorn
  • 24,970
  • 5
  • 40
  • 69
  • I know the operator but as my example above I keep receiving syntax errors. I can make it work up until I need to add in the operator and know matter what I try I keep getting syntax errors – Bender Sep 12 '20 at 21:42
0

In Python to calculate exponent you use ** operator. Similar to multiplication but double asterisk.

(((1+2)∗3)/4)**5

This will give you 32.

That is because you are using values which are all integers, so 9 / 4 will be 2, not 2.25.

Python has operator precedence that follows algebraic rules.

Lev M.
  • 6,088
  • 1
  • 10
  • 23