From e96c214f61eedd4b291815cb51b1fbcc9ad2a54f Mon Sep 17 00:00:00 2001 From: "G.Sureya Pragaash" <36239801+SUREYAPRAGAASH09@users.noreply.github.com> Date: Wed, 9 Jan 2019 19:26:57 +0530 Subject: [PATCH] counting the no of digits in a given integer this is a program for counting the no of digits in a given integer --- count.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 count.py diff --git a/count.py b/count.py new file mode 100644 index 0000000..4713144 --- /dev/null +++ b/count.py @@ -0,0 +1,20 @@ +Problem : + To count the no of digits given in a number +My Approach of giving Solution to the solution: + step 1 : First define a Funtion named as "countnumbers" + step 1.1 : In that, First initalize a variable named as count to Zero (to check how many digits are found in the given number after separation) + step 1.2 : Then, Run a while loop untill we separate all the integers from the given number + step 1.2.1 : initialize a "temp" variable and store the right most element of the digit + step 1.2.2 : Then, increment the count variable by 1 untill the while get ends + step 1.2.3 : store the remaining element of the digits after dividing it by 10 in a num and convert to int(num) (type conversio +Reason for using while loop : + I have used while loop instead of for loop because we could not make sure that when the number get ends + def countnumbers(num): + count = 0 + while (num>0): + temp = int(n) % 10 + count += 1 + num = int(num) / 10 + num = int(num) + + return count