Problem Statement
Given an integer n, find two integers a and b such that,
#a >= 0 and b >= 0
#a + b = n
#DigitSum(a) + Digitsum(b) is maximum of all possibilities
def solve(n):
len_of_n = len(str(n))
len_of_n-=1
a = '9'
a = (a*len_of_n)
#print(a)
b = (int(n) - int(a) ) # This is the line where it points to error.
#print(b)
digits_of_a = []
digits_of_b = []
for i in str(a)[::-1]:
digits_of_a.append(int(i))
for i in str(b)[::-1]:
digits_of_b.append(int(i))
return (sum(digits_of_a) + sum(digits_of_b))
The code actually reports correct answers on test cases on 'attempts' on codewars.com but fails final submission. It exits with error code 1. It says ValueError: invalid literal for int() with base 10: ''
I have read this other thread on this and understand that error is due to trying to convert a space character to an integer. Can't figure why would that statement get space charater. Both of them are int representations of string...?
nandawhen it hits the error? It And what are you passing into the function? The most likely thing, I think, is that the stringnis unable to be casted to an int, either because it's an empty string or because it has non-digit characters in it.