Thursday, 28 January 2021

Python program for Peterson number

Python program for Peterson number:

 

import math
num=int(input("Enter a number"))
m=num
sum=0
while num>0:

    rem=num%10
    fact=math.factorial(rem)
    sum=sum+fact
    num=num//10
if sum==m:
    print('Number is Peterson number')
else:
    print('Number is not a Peterson number')

 

Output 1: 

 

Peterson Number

Output :2


 


No comments:

Post a Comment