Home » Python » 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?**

Submitted by Anuj Singh, on June 04, 2019

Here, we are going to **calculate the value of N ^{th} power of a number without using power function**.

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 **N ^{th} 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

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.