Sinisterly
Need help with simple python math - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Python (https://sinister.li/Forum-Python)
+--- Thread: Need help with simple python math (/Thread-Need-help-with-simple-python-math)



Need help with simple python math - FurryRock - 02-01-2017

How am I getting two different results? I'm wanting to know what 2^3^4 is for practice. But I'm getting two different answers.

http://imgur.com/a/1qpLQ


RE: Need help with simple python math - Sikom - 02-01-2017

2^3^4 = 2^81 = 2.417852×10^24
(2^3)^4 = 2^3*4 = 2^12 = 4096

The two things are widely different, that's why you get different answers

Got me @FurryRock


RE: Need help with simple python math - FurryRock - 02-01-2017

(02-01-2017, 12:39 PM)SimPlaysGames Wrote: 2^3^4 = 2^81 = 2.417852×10^24
(2^3)^4 = 2^3*4 = 2^12 = 4096

The two things are widely different, that's why you get different answers

Got me @FurryRock

Man I need to go back to 9th grade, it looks like with knowledge of PEMDAS that the first equation would be:
2^3^4
8^4
4096

But apparently you need to solve 3^4 first, yeah I need to go back to school. Thanks tho. Smile


RE: Need help with simple python math - Desolate - 02-01-2017

Damn simplaygames is coming up in he world!!! good job bud Cool


RE: Need help with simple python math - Inori - 02-01-2017

It seems your problem is already resolved, but I would recommend using the builtin pow() method. It's implemented in C (in Python 3, anyway), so it executes faster than the double star (**) operator in any case I can recall, and it tends to be far less confusing in big equations if you're familiar with Python's syntax.

Code:
>>> (2**3)**4 4096 >>> pow(pow(2,3),4) 4096