Invalid literal for int with base 10: ''
11,904
n
might be numeric, but at some stage you're going past the length of n
such that n[previous:next]
contains no characters at all. The empty string ''
cannot be converted to an int, hence the error which tells the full story: invalid literal for int() with base 10: ''
.
>>> int('')
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: invalid literal for int() with base 10: ''
Author by
Marijus
Updated on June 05, 2022Comments
-
Marijus about 2 years
>>> n = ''.join(i for i in x if i.isdigit()) >>> n.isdigit() True >>> x.isdigit() False >>> previous = 0 >>> next = 100 >>> answer = 0 >>> for i in range(0,100): ... answer += int(n[previous:next]) ... previous = next ... next += 100 ... Traceback (most recent call last): File "<stdin>", line 2, in <module> ValueError: invalid literal for int() with base 10: ''
Why am I getting this error ? As you can see n is digit..