number of digits in a number python
n = 1234 //Any Random Number
digits = len(str(n)) //Saves the number of digits of n into the variable digits
number of digits in a number python
n = 1234 //Any Random Number
digits = len(str(n)) //Saves the number of digits of n into the variable digits
get length of an integer python
# Below uses constant space (converting to string and then gettings it's length does not)
num = 12362
count = 0
while num > 0:
count += 1
num = num // 10
print(count)
# for negative numbers, take absolue value first:
num = -12362
num = abs(num)
count = 0
while num > 0:
count += 1
num = num // 10
print(count)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us