Problem Set 6(Diffeve)

Q.A number ‘n’ is said to be a Diffeve number if the absolute value of the difference between the number ‘n’ and the reverse of ‘n’ is not zero. For example, 124 is Diffeve number. The absolute value of the difference between 124 and the reverse of 124 (reverse of 124 is 421) is 297.

Write an Algorithm and the subsequent Python code to check whether the given number is a Diffeve number or not.

Write a function to reverse a number

Input Format:


The first line will contain the number.

Output Format:


Print Diffeve number or Not a Diffeve number


Input:
the number

Processing:
def diffeve(n):
    temp = str(abs(n))[::-1]
    temp = int(temp)
    if abs(temp-n):
        print('Diffeve number')
    else:
        print('Not a Diffeve number')

Output:
display if the number is diffeve or not diffeve

Program:
def diffeve(n):
    temp = str(n)[::-1]
    temp = int(temp)
    if abs(temp-n):
        print('Diffeve number')
    else:
        print('Not a Diffeve number')
n = int(input())
diffeve(n)

Algorithm:
Step1. define the function diffeve with one parameter n
Step1.1 assign temp as the reverse of the number n obtained by string operations
Step1.2 convert the number back to an integer
Step1.3 if the absolute difference the number n and temp is non zero then display Diffeve else display Non diffeve
Step2. get the number n
Step3. call the function diffeve with n as the actual parameter
Step4. End

No comments:

Post a Comment

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...