As a newbie programmer

The Armstrong Number @ Dcoder

Dcoder icon

Problem: An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.

For example, consider the number 371. The sum of the cube of its digits is 3^3 + 7^3 + 1^3 = 27 + 343 + 1 = 371. Therefore, 371 is an Armstrong Number. Given a 3 digit integer, determine whether the number is Armstrong Number or not. If it is, print "YES" else print "NO", without the quotes.

Input: A 3-digit integer N.

Output: "YES" or "NO", without the quotes

Constraints: 100 ≤ N ≤ 999

Sample Input: 371

Sample Output: 

YES

n = int(input())
print('YES' if int((n//100)**3 + (n//10%10)**3 + (n%10)**3) == n else 'NO') 

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?