Find the number of integers from 1 to n which contains digits 0’s in Python

Here, we will see the python program totally what number of whole numbers from 1 to N contain 0’s as digits?

This instructional exercise going to most intriguing in light of the fact that we have seen

the whole number like 10, 20, 30, 40, 50, …, 100 and so on from 1 to 100 and one things ring a bell that this will effortlessly ascertain then why we use Python program to fathom the inquiry?

that is alright, however, think when the range is too huge then it will be entangled.

A number N will give by the client and we will discover what number of numbers have zero as digits up to the given worth N.

Thus, Here we will see the straightforward methodology in Python to explain it.

Prior to going to take care of the above issue, we will perceive how to check the given number has 0’s as digits or not?

Program:

# input the value of N
n=int(input('Enter the value of n: '))

s=str(n)
z=str(0)

if z in s:
    print('Zero is found in {}'.format(n))
else:
    print('Zero is not found in {}'.format(n))

Output:

RUN 1:
Enter the value of n: 39406
Zero is found in 39406

RUN 2:
Enter the value of n: 123456
Zero is not found in 123456

Here, we have perceived how to check the given number has zero as digits or not in Python? Presently, by utilizing the above ideas we will take care of the above issue in a basic manner.

program:

# enter the value of N
n=int(input('Enter the value of n: '))

c=0
z=str(0)

for j in range(1,n+1):
    if z in str(j):
        c+=1 
print('{} number has zero as digits up to {}.'.format(c,n))

Output:

RUN 1:
Enter the value of n: 50
5 number has zero as digits up to 50.

Run 2: 
Enter the value of n: 8348
2229 number has zero as digits up to 8348.

Run 3:
Enter the value of n: 9000
2349 number has zero as digits up to 9000.

Clarification:

Here, we have expected that the estimation of n gave by the client is 8348 and variable c used to

check the whole numbers which contain zero as a digit and at first, it relegates to zero. In the third line, we are utilizing for circle from 1 to n extent in which

we need to check whole numbers and by utilizing the in work we have done it. On the off chance that it has zero as a digit, at that point the estimation of c increased by 1.

So Guy’s, I trust you have comprehended this instructional exercise.

Leave a Comment

error: Alert: Content is protected!!