Write a program to accept a no and check whether it is a spy no or not.
Answers
Answered by
0
Answer:
In python,
_________________________
n=int(input("Enter a number to check: "))
b=str(n)
sum=0
pro=1
for i in range(0,len(b)):
sum+=int(b[i])
pro*=int(b[i])
if sum==pro:
print("Yes it's a spy number")
else:
print("No, it's not a spy number")
___________________________
Consider the image if you're having trouble understanding this.
Explanation:
A spy number has sum and product of all it's digits equal as for example 123.
Attachments:
Answered by
2
from math import prod
def spy_no(n):
digits = [int(n) for n in list(n)]
return "spy" if sum(digits) == prod(digits) else "not a spy"
n = input("enter a num: ")
print(spy_no(n))
Similar questions