Python uses for each loops, so iterating over numbers would require you to produce a sequence of numbers first. Python uses the range() type for this:
sum = 0
for i in range(len(factors)):
pass
Note that sum is assigned 0 explicitly, separately.
Usually however, you'd just loop over objects directly, rather than generate indices:
sum = 0
for element in factors:
pass
But if you are summing the factors, just use the sum() function:
total = sum(factors)
Note that I avoided using the name sum there to avoid masking the built-in function.
To multiply bytes from a sequence of bytes, just zip() the bytes and factors together:
sum = 0
for byte, factor in zip(string, factors):
sum += byte * factor
which can be collapsed with sum() and a generator expression:
total = sum(byte * factor for byte, factor in zip(string, factors))
This only works if string is a bytes object, not a Unicode str string object; bytes objects are really sequences of integers in the range 0-255.
If you wanted to interpret the characters as digits, use a Unicode string and use int() to convert each to an integer:
total = sum(int(digit) * factor for digit, factor in zip(string, factors))
Demo of the latter with the sample input you provided:
>>> sec_number = '0411994545'
>>> factors = [4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
>>> sum(int(digit) * factor for digit, factor in zip(string, factors))
164
>>> total = sum(int(digit) * factor for digit, factor in zip(string, factors))
>>> total % 11 == 0
False
Note that the == test already produces a boolean; there is no need to use a conditional expression in Python to produce a boolean result.
iandsum?factorsand expected output.