'How to solve the below code!? Armstrong number between given intervals in python
Need solution for python code!
How can we find the armstrong numbers in given interval.
I have written the code successfuly to identify the number, but could not be able to get the desired output.
My code :
lower = int(input())
upper = int(input())
for num in range(lower,upper + 1):
sum = 0
temp = num
armstrong = ""
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
armstrong = armstrong + (str(num) + " ")
print(armstrong)
Case - 1 Input : 150 200
Expected out put : 153 This case was successful.
Case - 2: Input : 1 3
Expected output : 1 2 3 Could not get the proper output for this one!
Solution 1:[1]
The code you have written only works for numbers between 100 and 999 because of line:
sum += digit ** 3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kilian |
