Robotics & Artificial Intelligence
Write a program to input a number. Check and display whether it is a Niven Number or not. (A number is said to be Niven when it is divisible by the sum of its digits).
Sample Input: 126
Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.
Python Control Flow
2 Likes
Answer
n = int(input("Enter a number: "))
p = n
s = 0
while n > 0:
d = n % 10
s = s + d
n = n // 10
if p % s == 0:
print(p, "is a Niven Number")
else:
print(p, "is not a Niven Number")Output
Enter a number: 126
126 is a Niven Number
Enter a number: 167
167 is not a Niven Number
Answered By
2 Likes
Related Questions
Write a Python code to check and display whether a number input by the user is a composite number or not.
[A number is said to composite, if it has one or more factors excluding 1 and the number itself. For example: 4, 6, 8, 9, ……………]
Write a program to input 10 different numbers. Display the greatest and the smallest numbers among them.
Write a program to input a number and display the new number after reversing the digits.
Sample Input: 467
Sample Output: 764
Write a Python code to display the Mathematical Tables from 5 to 10. Each Mathematical Table should run for 10 iterations as shown in the given format:
Sample Output: Table of 5
5*1 = 5 5*2 = 10 ............... ............... 5*10 = 50