Dremendo Tag Line

Input a number and check if it is a duck number or not using a function in Python

Function - Question 5

In this question, we will see how to input a number and check if it is a duck number or not in Python programming using a function. To know more about function click on the function lesson.

Q5) Write a program in Python to input a number and check if it is a duck number or not using a function. The function should return 1 if the numbers is a duck number else return 0.

A duck number is a number which has zero present in it.

Example: 3210, 7056, 35070, etc.

Program

def ducknumber(num):
    while num>0:
        d=num%10
        if d==0:
            return 1
        num=num//10
    return 0


# main program
n=int(input('Enter a number '))
if ducknumber(n)==1:
    print('Duck Number')
else:
    print('Not Duck Number')

Output

Enter a number 73062
Duck Number
video-poster