I want to count number of digits of any digits number without converting the number to string and also using for loop. Can someone suggest how to do this.
num = int(input("Enter any number : "))
temp = num
count = 0
for i in str(temp):
temp = temp // 10
count = 1
print(count)
CodePudding user response:
i = int(input('num : '))
j=0
while i:
j =1
i//=10
print(j)
CodePudding user response:
If you stick to using input
, you can't get away the fact that this function prompts a String
. As for the for
loop, simply count the number of characters in the input string:
num = input("Enter any number : ")
print(len(num))