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

6th Oct 2016, 7:33 AM
alex slater
alex slater - avatar
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.
6th Oct 2016, 7:39 AM
ZoltĂĄn ZörgƑ
ZoltĂĄn ZörgƑ - avatar
+ 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)
7th Oct 2016, 7:49 PM
Waseem
Waseem - avatar
0
thank you
6th Oct 2016, 7:48 AM
alex slater
alex slater - avatar