Computer Science, asked by rudratejamoyya1394, 1 year ago

Write a program to accept a no and check whether it is a spy no or not.

Answers

Answered by allysia
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 jai696
2

\large\mathsf\color{pink}{Solution\: using\: python\: 3}

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))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions