Code is keep on running , please help in finding the error

def power(num):
global n
n=0
temp = num
while num >0:
digit = temp //10
n = n +1
temp = temp // 10

def armstrong(num):
sum =0
temp = num
while temp>0:
digit = temp // 10
sum = sum + (digit**power(num))
temp = temp // 10
if sum == num:
print (“The number is armstrong number”)
else:
print(“The number is not armstrong number”)
num = int(input(“Enter the number”))
armstrong(num)

Hey @goley005,
Run this code on coding blocks IDE and share the link of it.
Link of Coding Blocks IDE- Click Here

Hi Rishabh
Link of the code:

Hey @goley005,
First of all there is no indentation in the code as because of this Python is unable to specify a block of code. Apply indentation in every block.

Hi Rishabh

Hey @goley005,
Why are you using power function in your code repeatedly instead you can just count the number of digits once and then use the count as power for every digit.

So , instead of using power function I should just count the number of digits and use that value as power.
Only one function then which is to find the Armstrong number.

Ya that would be a better approach for the question as it will decrease time complexity of the code.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.