Alternative code : n=input("enter your number : ") sum=0 for i in range(len(n)): r=int(n[i])**len(n) sum+=r if (int(n)==sum): print("it's an armstrong number") else: print("not an armstrong number")
Code for checking a armstrong number for n digit number: num=int(input("Enter the numbers:")) sum=0 degree=len(str(num)) temp=num while temp>0: digit=temp%10 sum+=digit**degree temp//=10 if num==sum: print(f"{num} is an amstrong number") else: print(f"{num} is not an amstrong number")
Pro Tip: Try to make the program by yourself first user = input('Koi number input karo : ') n = len(user) arms = 0 user = (int(user)) temp = user while (temp != 0): rem = temp % 10 arms += rem ** n temp = temp // 10 # '//' performs integer division if user == arms: print ('Armstrong number!') else: print('Not an Armstrong Number!')
num = int(input("Enter a n-digit number : ")) n = len(str(num)) temp = num sum = 0 while temp > 0: digit = temp%10 sum = sum + digit ** n temp = temp //10 if (num == sum): print(f"{num} is an Armstrong number") else: print(f"{num} is not an Armstrong number") OUTPUT:- Enter a n-digit number : 1234 1234 is not an Armstrong number Enter a n-digit number : 153 153 is an Armstrong number
Alternative code :
n=input("enter your number : ")
sum=0
for i in range(len(n)):
r=int(n[i])**len(n)
sum+=r
if (int(n)==sum):
print("it's an armstrong number")
else:
print("not an armstrong number")
thnx
Alternate code:
n=input()
sum=0
for i in n:
sum+=int(i)**len(n)
if(sum==int(n)):
print("yes")
else:
print("no")
Code for checking a armstrong number for n digit number: num=int(input("Enter the numbers:"))
sum=0
degree=len(str(num))
temp=num
while temp>0:
digit=temp%10
sum+=digit**degree
temp//=10
if num==sum:
print(f"{num} is an amstrong number")
else:
print(f"{num} is not an amstrong number")
Bro, Please Do A Playlist On Machine Learning That Have
1) Concepts
2) Diagram
3) Examples
4) Python Programs
5) Related Concepts
E-> E+E|E-E| id output id-id*id Ambiguity in cfg problem sol the rightmost derivation nd ieft most derivation
Pro Tip: Try to make the program by yourself first
user = input('Koi number input karo : ')
n = len(user)
arms = 0
user = (int(user))
temp = user
while (temp != 0):
rem = temp % 10
arms += rem ** n
temp = temp // 10 # '//' performs integer division
if user == arms:
print ('Armstrong number!')
else:
print('Not an Armstrong Number!')
Nice
Next Boyer-Moore Algorithm with bad character heuristic.
num = int(input("Enter a n-digit number : "))
n = len(str(num))
temp = num
sum = 0
while temp > 0:
digit = temp%10
sum = sum + digit ** n
temp = temp //10
if (num == sum):
print(f"{num} is an Armstrong number")
else:
print(f"{num} is not an Armstrong number")
OUTPUT:-
Enter a n-digit number : 1234
1234 is not an Armstrong number
Enter a n-digit number : 153
153 is an Armstrong number