Hello everyone, welcome back to programminginpython.com! Here in this post I will show you how to find the number of digits in a number. A pretty simple logic. [embedyt] https:\/\/www.youtube.com\/watch?v=bpBBcymXP0U[\/embedyt] You can watch this video …<\/p>","author":{"@type":"Person","name":"AVINASH NETHALA","url":"https:\/\/www.programminginpython.com\/author\/avinash\/","image":{"@type":"ImageObject","url":"https:\/\/secure.gravatar.com\/avatar\/ed52e7670d7db94820c7430d324103ccdecb16d86611d5b29064aa9ce25a958b?s=96&d=mm&r=g","height":96,"width":96},"sameAs":["https:\/\/www.programminginpython.com\/"]}}

Home » Python program to find number of digits in a number

Python program to find number of digits in a number

Python program to find number of digits in a number Python program to find number of digits in a number

Hello everyone, welcome back to programminginpython.com! In this post, I will show you how to find the number of digits in a number. It is pretty simple logic.

https://www.youtube.com/watch?v=bpBBcymXP0U”]

You can watch this video on Youtube here

Program on GitHub

Find the number of digits in a number – Code Visualization

Task

To find the number of digits in a given number.

Approach

  • Read the number whose digits to be counted.
  • Use a while loop to get each digit of the number using a modulus // operator
  • Increment after a digit is obtained.
  • Continue until the value of the number is 0
  • Print the total count(number of digits) of the number.

Program on GitHub

Program

__author__ = 'Avinash'

input_num = int(input('Enter any number: '))

count = 0
while input_num > 0:
    count += 1
    input_num //= 10
print("The number of digits in the given number are:", count)

Program on GitHub

Output

Find number of digits in a number

Find number of digits in a number

 

You can watch this video on Youtube here

 

Online Python Compiler

Leave a Reply

Your email address will not be published. Required fields are marked *