Your formula is completely off. There are not additions in powers. a3 = a * a * a, a4 = a * a * a * a Think about how you can convert that into a loop. You take a starting point a, then, you multiply that starting point with a, next time, you again multiply the result from before by a, and so on until you have your power. Also, why are you using eval? You should make explicit type conversions using int or float. total should either start at a or at 1, not at 0. Answer from desrtfx on reddit.com
🌐
Zero To Mastery
zerotomastery.io › blog › python-exponent
Beginner's Guide to Python Exponents (With Code Examples) | Zero To Mastery
This flexibility is invaluable in data analysis, allowing you to model complex changes quickly without recalculating each scenario by hand. As you’ve seen, exponents are more than just math—they’re a powerful way to simplify complex calculations and make your code cleaner and faster. Whether you’re automating financial models, analyzing data, or tackling scientific problems, Python...
🌐
Flexiple
flexiple.com › python › python-exponents
Exponent in Python – Power Function and Exponents Using a Loop - Flexiple
In this code, the loop runs 4 times, each time multiplying the result by the base (2). After completing the loop, result holds the value of 16, which is 2 raised to the power of 4. This technique demonstrates a fundamental approach to calculating powers without using built-in functions or operators. Mastering the concept of exponentiation in Python is a powerful tool in your programming arsenal. From using the simple exponent operator ** to leveraging built-in functions like pow and math.pow(), or even iterating with loops for manual calculations, Python offers diverse ways to perform these operations.
🌐
Quora
quora.com › How-do-I-make-a-number-an-exponent-of-another-in-Python-without-using-the-inbuilt-‘**’-or-the-‘math-pow’
How to make a number an exponent of another in Python without using the inbuilt ‘**’ or the ‘math.pow’ - Quora
Answer (1 of 4): There are many ways to approach this. Just write your own function! [code]def power(a,b): res = 1 for i in range(b): res *= a return res [/code]This is one of the snippets which works and returns a^b.
🌐
W3Schools
w3schools.com › python › ref_func_pow.asp
Python pow() Function
Built-in Modules Random Module ... Q&A Python Bootcamp Python Certificate Python Training ... The pow() function returns the value of x to the power of y (xy)....
🌐
Thomascollart
thomascollart.com › python-power
How to Calculate Power of a Number in Python?
December 21, 2023 - Raising to the power with the double asterisks ** is slightly faster than pow() or math.pow(). This is mainly because Python does not have to call a function but uses the operator directly.
🌐
Ben
ben.land › post › 2021 › 02 › 24 › power-without-math-lib
Implementing exponentiation without a standard math library | ben.land
This results in the following implementation, where the ftol parameter sets the maximum value the next term can take before the calculation terminates. Note the use of ipow from earlier to compute the integer powers.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › write-you-own-power-without-using-multiplication-and-division
Write you own Power without using multiplication(*) and division(/) operators - GeeksforGeeks
Interview Corner · DSA Python · Last Updated : 23 Jul, 2025 · Method 1 (Using Nested Loops): We can calculate power by using repeated addition. For example to calculate 5^6. 1) First 5 times add 5, we get 25.
Published   July 23, 2025
🌐
Real Python
realpython.com › lessons › power-functions
Power Functions (Video) – Real Python
So even though in math we usually don’t define 0 raised to the power of 0—we leave it undefined—in the math module, it returns 1.0 Let’s try some examples with the power function.
Published   August 24, 2021
🌐
Oreate AI
oreateai.com › blog › unlocking-pythons-math-power-a-friendly-guide-to-importing-and-using-the-math-module › 4d5eddad8574a72a842756ca6943ecdc
Unlocking Python's Math Power: A Friendly Guide to Importing and Using the `Math` Module - Oreate AI Blog
2 weeks ago - Sometimes, you might only need a specific tool from the math module, like the square root function. In this case, you can use from math import sqrt. After this, you can use sqrt() directly without the math.
🌐
DataCamp
datacamp.com › tutorial › exponents-in-python
Exponents in Python: A Comprehensive Guide for Beginners | DataCamp
November 25, 2024 - Squaring in Python is easy: Use the in-built ** operator or try NumPy, pow(), math.pow(), bitwise operators, and other functions for more versatile solutions. ... Many Python users are familiar with using asterisks for multiplication and power operators, but in this tutorial, you'll find out additional ways on how to apply the asterisk.
🌐
Quora
quora.com › How-can-powers-exponents-be-calculated-easily-in-Python
How can powers (exponents) be calculated easily in Python? - Quora
Answer: You can use the ** operator, e.g: x = 2 ** 3 # x = 8.0 y = 9 ** 0.5 # y = 3.0 Note that the ** operator has a precedence over a sign. Therefore, we get: z1 = -1 ** 0.5 # z1 = -1.0 However, if we use parentheses, we get: z2 = (-1) ** ...
🌐
Reddit
reddit.com › r/python › why is the power operator much slower than multiplication in python?
r/Python on Reddit: Why is the power operator much slower than multiplication in Python?
January 30, 2022 -

I was writing some code in Python, and usually when typing up equations, I use x**2 to calculate the value of a variable squared. I had seen it typed as x*x a few times, and was curious about the speed difference between the two, so I ran a timeit test on both and expected both to be almost exactly the same since the two are mathematically equivalent expressions.

When I ran the benchmarks, I saw that using plain multiplication was almost 9-10x faster than just using the power operator. Even (sometimes) for 4, 5, 6, and much higher exponents, python's multiplication was still faster by a few times, if not, more.

I inspected the bytecode, and found that Python uses binary power for the power operator, and binary multiplication for the multiplication operator, and for some reason, that is faster than power. While I understand that both use different operations, why hasn't this become an optimization at the interpreter level, especially since having to write x*x*x*x*x is not that practical vs x**5 to get a speedup in your code?

I applied multiplication instead of power to some of my code that did calculations, and found a significant speed increase for algorithms that I otherwise would've thought were as fast as they possibly could be in Python.

🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
In Python 3 without the Math package, what is the equivalent of ceiling and floor? - Raspberry Pi Forums
Mathematica · High Altitude Balloon · Weather station · Programming · C/C++ Java · Python · Scratch · Other programming languages · Windows 10 for IoT · Wolfram Language · Bare metal, Assembly language · Graphics programming · OpenGLES · OpenVG ·
🌐
Reddit
reddit.com › r/swift › calculate the power of a number without using the pow() function?
r/swift on Reddit: Calculate the power of a number without using the pow() function?
November 22, 2020 -

I've set out on a dumb project of optimizing every little thing in a decimal -> binary converter. The largest "performance" issue right now is that using the pow function takes quite a bit longer than just multiplying it with simple operators. In the following code, the pow function takes about 26ms where the simple calculations take roughly 0.1ms.

// ~26ms
timeElapsedInSecondsWhenRunningCode {
    let value: Decimal = pow(2, 64)
    print(value)
}

// ~0.1ms
timeElapsedInSecondsWhenRunningCode {
    let value: Decimal = 2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2
    print(value)
}

In a real world use case, I would just use the pow function but since my goal here is to create something over-optimized... how can I calculate a power without using the pow function?

🌐
GeeksforGeeks
geeksforgeeks.org › python-program-to-find-power-of-a-number
Python program to find power of a number - GeeksforGeeks
February 21, 2025 - The task of calculating the square ... 4, its square is 16 because 4 × 4 = 16.Using ** operatorexponentiation operator (**) is the most direct and optimized way to compute powers....