Given indices are just repeated multiplication, you could use the for loop to progressively multiply it.
Something like:
n = 5
runningPower = 1
for i in range(n + 1):
runningPower *= 2
print(runningPower)
Answer from zjb on Stack Overflow Top answer 1 of 3
3
Given indices are just repeated multiplication, you could use the for loop to progressively multiply it.
Something like:
n = 5
runningPower = 1
for i in range(n + 1):
runningPower *= 2
print(runningPower)
2 of 3
1
As we all know, pow is just repeated multiplication.
So, we can create a loop that on every iteration it'll multiply a variable (we'll declare a variable that his starting value is 1) by 2.
Example code:
powers = 1 # Declare variable.
for pow in range(10): # Set a loop for range(10).
print(powers) # Print the variable.
powers *= 2 # Power it by 2.
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
[Python] Im trying to make a program that manually calculates powers without the use of ** or any other function. Help?
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. More on reddit.com
How to raise a number to the power of another without Math.pow() ?
You might want to see if a for loop would be useful. More on reddit.com
Videos
03:59
Python Power: A Step-By-Step Guide | Using exponents in python ...
Python math.pow - YouTube
00:52
Python pow() function | math module | mathematical functions - YouTube
09:46
Understanding Python's Power Operator: Fundamentals Explained by ...
05:47
Python Program #81 - Compute the Power of a Number in Python - YouTube
pow Python Function | Mastering Exponentiation for Python Beginners ...
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.
Reddit
reddit.com › r/learnprogramming › [python] im trying to make a program that manually calculates powers without the use of ** or any other function. help?
r/learnprogramming on Reddit: [Python] Im trying to make a program that manually calculates powers without the use of ** or any other function. Help?
September 7, 2022 -
def power():
a = eval(input("enter base: "))
b = eval(input("enter exponent: "))
total = 0
for x in range(0,b+1):
total = (total) + (a*a)
print(total) Top answer 1 of 3
1
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.
2 of 3
1
First, don't use eval. There are almost always better ways to do whatever it is you want to do without it. In this case, just use int() or float() to parse the input into a number. Second, your formula is incorrect. What you're doing is adding squares. What you actually want to do is multiply a times itself b times. Consider the *= operator: x = 5 x *= 5 print(x) #prints 25 x *= y is the equivalent of x = x * y. See if you can use what I've said to re-write your program.
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)....
Zero To Mastery
zerotomastery.io › blog › python-exponent
Beginner's Guide to Python Exponents (With Code Examples) | Zero To Mastery
November 8, 2024 - 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...
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
November 16, 2022 - 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 ·
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.
TutorialsPoint
tutorialspoint.com › how-to-perform-square-root-without-using-math-module-in-python
How to perform square root without using math module in Python?
Without using the math module, the simplest approach to find the square root of a number in Python is to use the built-in exponential operator ** (It is an exponent operator because it calculates the power of the first operand to the power of the second operand).
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › pow
Math.pow() - JavaScript | MDN
In addition, the behavior where base is 1 and exponent is non-finite (±Infinity or NaN) is different from IEEE 754, which specifies that the result should be 1, whereas JavaScript returns NaN to preserve backward compatibility with its original behavior. Because pow() is a static method of Math, use it as Math.pow(), rather than as a method of a Math object you created (Math is not a constructor).
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-find-power-of-a-number
Python program to find power of a number - GeeksforGeeks
July 23, 2025 - This is the simplest and most Pythonic way to calculate the power of a number. The ** operator is internally optimized and is the preferred choice for most situations.
Automate the Boring Stuff
automatetheboringstuff.com › 3e › chapter1.html
Chapter 1 - Python Basics, Automate the Boring Stuff with Python, 3rd Ed
Be sure you don’t run python on ... Python 2.7 is not recommended. Exit the 2.7 interactive shell and run python3 instead. Enter 2 + 2 at the prompt to have Python do some simple math....
W3Schools
w3schools.com › python › ref_math_pow.asp
Python math.pow() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... # Import math Library import math #Return the value of 9 raised to the power of 3 print(math.pow(9, 3)) Try it Yourself »