Saturday, November 16, 2024
Google search engine
HomeLanguagesPython Program to Find Number of Integers From 1 to n Contains...

Python Program to Find Number of Integers From 1 to n Contains Digits 0’s

Python program to find and count the number of occurrences of 0’s in integers from 1 to N; In this tutorial, you will learn how to find and count integers from 1 to N contain 0’s and 1’s as digits.

How to check if a number contains 0’s digit From 1 to N in python

  • Python Program 1: Find the number of integers from 1 to n which contains digits 0’s
  • Python Program 2: Find the number of integers from 1 to n which contains digits 0’s
  • Python Program 3: Find the number of integers from 1 to n which contains digits 0’s and 1’s

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

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

# 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

Enter the value of n:  10
Zero is found in 10

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

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

# 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))

.box-4-multi-260{border:none!important;display:block!important;float:none!important;line-height:0;margin-bottom:15px!important;margin-left:auto!important;margin-right:auto!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:250px;padding:0;text-align:center!important;width:100%}

Output

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

Python Program 3: Find the number of integers from 1 to n which contains digits 0’s and 1’s

# Python Program to Find the number of integers 
# from 1 to n which contains 0's and 1's only 

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

def countNumbers(x, n): 
	
	# If number is greater than n 
	if x > n : 
		return 0

	# otherwise add count this number and 
	# call two functions 
	return (1 + countNumbers(x * 10, n) +
				countNumbers(x * 10 + 1, n)) 

# Driver code 
if __name__ == '__main__': 

	print('The count is ', countNumbers(1, n)); 

Output

Enter the value of n:  200
The count is  7

Recommended Python Programs

  1. Python Program to Find/Calculate Average of 3, 4, 5…n numbers
  2. Python Program to Print ASCII Value of Character
  3. Write a Program to Calculate Simple Interest in Python
  4. Python Program to Compute Compound Interest
  5. Leap Year Program in Python
  6. Python Program to Print Star Pattern
  7. Number Pattern Programs in Python
  8. Python Program to Print Even and Odd numbers From 1 to N
  9. Python Abs() Function: For Absolute Value
  10. How to Check Whether a Number is Fibonacci or Not in Python
  11. Python: Program to Find Power of Number
  12. Python Program to Reverse a Numbers
  13. Python Program to Find Smallest/Minimum of n Numbers
  14. Python Program to Calculate Cube of Number
  15. Python Program to Find LCM of Two Numbers
  16. BMI (Body Mass Index) Calculator in Python
  17. Palindrome Program in Python using while loop, Function, etc
  18. Python: Program to Count Total Number of Bits in Number
  19. Python Random Number Generator Code
  20. Python Program to Calculate n-th term of a Fibonacci Series
  21. Zip Zap Zoom Python Program
  22. Python: program to convert Celsius to Fahrenheit
  23. Python Program to Swap Two Numbers
  24. Python Program to Get Standard Deviation
  25. Python Program to Find the Variance
  26. Python Program to Convert Height in cm to Feet and Inches
  27. Python Program to Convert Meters into Yards, Yards into Meters
  28. Python Program to Convert Kilometers to Meters, Miles
  29. Python Program to Find Perfect Number
  30. Python: Program to Find Strong Number
  31. Python Program Create Basic Calculator
  32. Python Program For math.floor() Method
  33. Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!
  34. Python: Program to Convert Decimal to Binary, Octal and Hexadecimal
  35. Python Program to Find Roots of Quadratic Equation
  36. Python Program to Print Alphabets from A to Z in Uppercase and Lowercase
  37. Python Program to Check Given Input is Alphabet, Number or Special Character
  38. Python Program to Check IF a Number is Power of Another Number
  39. Python Check Binary Representation of Given Number is Palindrome or Not
  40. Python Program to Find Area and Circumference of Circle using Radius
  41. Python Program that Accepts Marks in 5 Subjects and Outputs Average Marks
  42. Python Program to Print Binary Value of Numbers From 1 to N
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments