0% found this document useful (0 votes)
78 views3 pages

Program 9. User Defined Module - 1 Aim

This program creates a module called NUMBER that contains two functions - palindrome() and splnum(). palindrome() checks if a number is a palindrome by comparing the original and reversed number. splnum() checks if a number is special by calculating the sum of the factorials of its digits and comparing to the original number. The main program imports NUMBER, uses palindrome() to check numbers in a tuple, and uses splnum() to find special numbers between limits provided by the user and prints the results.

Uploaded by

vimala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views3 pages

Program 9. User Defined Module - 1 Aim

This program creates a module called NUMBER that contains two functions - palindrome() and splnum(). palindrome() checks if a number is a palindrome by comparing the original and reversed number. splnum() checks if a number is special by calculating the sum of the factorials of its digits and comparing to the original number. The main program imports NUMBER, uses palindrome() to check numbers in a tuple, and uses splnum() to find special numbers between limits provided by the user and prints the results.

Uploaded by

vimala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM 9.

USER DEFINED MODULE – 1


AIM:
Create a module NUMBER to include the following functions, with each function to include
docstrings to describe the function. Also write a python code to import this module and use
the two functions for inputs from the user.
i) palindrome() to take as parameter a number and returns 1 if the number is a palindrome
and –1 otherwise. This function to be tested with a tuple of integers
ii) special() – takes as parameter a number and returns 1 if it’s a special number and -1
otherwise. [ A special number is a number equal to the sum of the factorial of the individual
digits of the number] This function to be tested to generate list of special numbers between
two limits accepted from the user.

PROGRAM CODING
#NUMBER.PY
#palindrome without using strings
def palindrome(num):
''' A Number is said to be Palindrome if the original
and the reverse number are same'''
b=0
temp=num
while num>0:
a=num%10
b=b*10+a
num=num//10
if temp==b: return 1
else: return -1
def splnum(num):
'''A special number is a number equal to the sum
of the factorial of the individual digits of the number'''
import math
s,b,tem=0,0,num
while num>0:
a=num%10
s+=math.factorial(a)
num=num//10
if s== tem:
return 1
else:
return -1
#******* PROGRAM9.PY
import NUMBER
print("\t\t\tTo check palindrome numbers from a tuple ")
print("\t\t\t",'*' * 45)
t=tuple()
n=int(input('Enter the no.of entries:'))
for i in range(n):
num=int(input('Enter a number:'))
t+=(num,)

for i in t:
if NUMBER.palindrome(i)==1:
print(i,'is a palindrome')
else:
print(i,'is not a palindrome')

print("\t\t\tTo check special numbers from a range ")


print("\t\t\t",'*' * 40)

lower=int(input("Enter the lower limit"))


upper=int(input("Enter the upper limit"))
lst=[]
for j in range(lower,upper+1):
if NUMBER.splnum(j)==1:
lst.append(j)
if lst==[]:
print("No special number between the given limit")
else:
print("Special number between the given limit is",lst)
OUTPUT
To check palindrome numbers from a tuple
*********************************************
Enter the no.of entries:5
Enter a number:23
Enter a number:44
Enter a number:56
Enter a number:77
Enter a number:121
23 is not a palindrome
44 is a palindrome
56 is not a palindrome
77 is a palindrome
121 is a palindrome
To check special numbers from a range
****************************************
Enter the lower limit10
Enter the upper limit1000
Special number between the given limit is [145]
>>>

You might also like