Home » Python » Python programs

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

Here, we will see the **python program to count how many integers from 1 to N contain 0's as digits?**

Submitted by Bipin Kumar, on November 21, 2019

This tutorial going to most interesting because we have seen integer like **10, 20, 30, 40, 50, ..., 100** etc from **1 to 100** and one things come to our mind that this will easily calculate then why we use Python program to solve the question? that's ok but think when the range is too large then it will be complicated. A number N will provided by the user and we will find how many numbers have zero as digits up to the given value N. So, Here we will see the simple approach in Python to solve it.

Before going to solve the above problem, we will see **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 seen **how to check the given number has zero as digits or not in Python?** Now, by using the above concepts we will solve the above problem in a simple way.

**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.

**Explanation:**

Here, we have assumed that the value of n provided by the user is **8348** and variable c used to **count the integers which contain zero as a digit** and initially, it assigns to zero. In the third line we are using for loop from 1 to n range in which we have to check integers and by using the in function we have done it. If it has zero as a digit then the value of c incremented by 1. So Guy's, I hope you have understood this tutorial.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.