0

how to write a program to check amstrong number

27th Oct 2016, 2:36 AM
midhun k r
2 Respostas
+ 3
Here It Is num = int(input("Enter the number : ")) order = len(str(num)) sum = 0 temp = num while temp > 0: digit = temp % 10 sum += digit ** order temp //= 10 if num == sum: print (num, "is an Armstrong number") else: print (num, "is not an Armstrong number") If you don't understand it ... I will explain it to you in detail
27th Oct 2016, 7:41 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 2
Taking a quick peek online at how Armstrong/Narcissistic numbers are generated: http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/arms.html Perhaps you want to know how to split a number into digits? (everything else you need to know is taught in the app I think) >>> string_int="31427" >>> list(string_int) ['3', '1', '4', '2', '7']
27th Oct 2016, 6:51 AM
Kirk Schafer
Kirk Schafer - avatar