×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python program to find the power of a number using loop

Finding power of a number in Python: Here, we are going to learn how to find the power of a number using loop in Python? By Anuj Singh Last updated : April 09, 2023

Here, we are going to calculate the value of Nth power of a number without using power function.

Power of a number using loop

The idea is using loop. We will be multiplying a number (initially with value 1) by the number input by user (of which we have to find the value of Nth power) for N times. For multiplying it by N times, we need to run our loop N times. Since we know the number of times loop will execute, so we are using for loop.

Example

Input:
base: 5, power: 4

Output:
625

Python code to find power of a number using loop

num = int(input("Enter the number of which you have to find power: "))
pw = int(input("Enter the power: "))

kj = 1
for n in range(pw):
    kj = kj*num

print(kj)

Output

Enter the number of which you have to find power: 5
Enter the power: 4
625

Python Basic Programs »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.