Module: (Python) Conditional loop statement - WHILE


Problem

6/21

Number digits

Theory Click to read/hide

Task

You must enter a number (let it be less than 3,000,000) and determine the number of digits in it.
 
Idea of ​​solution
We just need to sequentially cut off the last digit from the number (this can be done by reducing the number by 10 times, using integer division by 10), and each time we need to increase the counter. 

As a result, after we cut off all the digits of the number, we will get their number in the counter.

This algorithm can be formulated as follows:
Until the number is zero, decrease it by 10 and increment the counter by 1 each time.
 
number (n) counter
123 0
12 1
1 2
0 3

The program will look like this. n = int(input()) count = 0 while n != 0: count += 1 n = n // 10 print("Number -", n, "contains", count, "digits")
You need to know this program by heart, because. on its basis, many other tasks related to the processing of digits of a number are solved.

Problem

Run the program. 

Look at the result of her work.
Is everything okay in the output phrase? Think about how you can fix this problem.