0
i need help
so im trying to make a program where i put in a number but i need the length of the number between 7 and 10 i have if len(number)<7 or len(number)>10 print(not valid) but it says int has no len
3 Answers
+ 4
A number has no length. You can either convert it to a string to get the length:
len(str(number))
Or calculate it's log10 rounded up. The later is more resource effective approach. And even when converting you could store the result in a variable and not recalculate it twice.
+ 1
#just check the length of the input string before converting to integer.for example
number=input ("Enter the number")
if len(number)< 7 or len(number)>10:
print('Enter a number between 7 to 10 in length')
else:
number =int(number)
0
thank you