I think this question is more complex than it seems because it has many different parts!
We'll need first to use a List Comprehension and str() since a .split() won't help us make 860007386 into a separate list of numbers since we don't have an identifier between the numbers to use inside .split(). If we had spaces between 860007386 we could have used .split(' '), or if we had numbers separated by - we could have used .split('-') as the identifier to split.
Therefore, you'll need a List Comprehension to iterate the index position of each number in the string to split them, like this:
Create two variables.
[1] largenum = 860007386
[2] nummul = [41, 37, 29, 23, 19, 17, 13, 7 , 3]
First, convert largenum into a string and assign it to a variable.
[3] str_largenum = str(largenum)
Now, you'll see, as I mentioned before .split will not separate the numbers in the string variable, instead it will give you only one string:
In[4] str_largenum.split()
Out[5] ['860007386']
To solve this problem, we'll use a List Comprehension, going from a range 0 to the length of largenum as a string, so from 0 to 9. For each index i in the range, which is the same number of numbers in largenum, you'll create a list of strings by selecting the index location of str_largenum from i to i+1. The i:i+1 is the indexing slicing that separates each string (each number) for us.
In[6] print([str_largenum[i:i+1] for i in range(0,len(str_largenum),1)])
['8', '6', '0', '0', '0', '7', '3', '8', '6']
I create a variable called split_str_largenum to assigned the List Comprehension to create the separate string of numbers.
[7] split_str_largenum = [str_largenum[i:i+1] for i in range(0,len(str_largenum),1)]
Now, you'll have to convert the List of strings back into integers with a List Comprehension.
[8] [int(numstring) for numstring in split_str_largenum]
And now assign this to a new variable called integer_split_largenum
[9] integer_split_largenum = [int(numstring) for numstring in split_str_largenum]
[10] print(integer_split_largenum)
[8, 6, 0, 0, 0, 7, 3, 8, 6]
So now we have to Lists, which in Python can be thought as List arrays.
[8, 6, 0, 0, 0, 7, 3, 8, 6]
[41, 37, 29, 23, 19, 17, 13, 7 , 3]
Now we need to use Linear Algebra, and take both of these arrays and multiple them.
For this, we'll need to import numpy package, and do a dot product multiplication to multiple each number in both arrays and add them. First, we will convert both variables with the list arrays into numpy arrays with np.array(); then use the np.dot() function.
[11] import numpy as np
a = np.array(integer_split_largenum)
b = np.array(nummul)
dotproduct = np.dot(a,b)
which gives you 782
[12] residual = dotproduct / 11
[13] print(residual)
71.0909090909091
[14] verification_code = residual - 11
print(verification_code)
60.09090909090909
I think this what you are looking for. Let me know if you have any questions.