What is Armstrong number
Armstrong number of three digits is an integer such that the sum of the cubes of the digits is equal to the number itself.
The game works with a timer so we give a player time to think.
It's modified to ask your name.
Fun with Visual Studio
Let's have fun generating Armstrong Number
We find the sum of the cube of each digits
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
The Python logic
- # Python program to check if the number provided by the user is an Armstrong number or not
-
- # take input from the user
- num = int(input("Enter a number: "))
-
- # initialise sum
- sum = 0
-
- # find the sum of the cube of each digit
- temp = num
- while temp > 0:
- digit = temp % 10
- sum += digit ** 3
- temp
-
- # display the result
- if num == sum:
- print(num,"is an Armstrong number")
- else:
- print(num,"is not an Armstrong number")
Open up Visual Studio
After that open a Visual Studio project with
Python,
The program
Will try with 2 numbers.
Let's try 346,
Now 371,
It's an Armstrong Number.
Cubing numbers: 3*3*3 + 7*7*7 + 1= 371 (Armstrong Number)
Conclusion
We will go through lots of tricky logic and a simple one with Visual Studio in Python. We see it's very easy to implement it.
Read more articles on Python: