The type of data
is a list with strings, not a list of integers:
>>> data=list(input("Enter a 7-bit binary integer:"))
Enter a 7-bit binary integer:123456
>>> data
['1', '2', '3', '4', '5', '6']
As such, you're trying to concatenate strings and you're not summing numbers as expected:
if (data[0]+data[1]+data[3]+data[4]+data[6])%2 == 0:
To fix it, you'll need to change all the strings into numbers first:
data = [int(x) for x in data]
At the moment this line is adding the strings in the list back together to a single string and you're trying to use string formatting on that string (with % 2
which the syntax for string formatting). The operator %
is the modulo operator when applied to a number but it's the string formatting operator when applied to a string.
In other words, you're doing:
'123456' % 2
which means Python is trying to insert that 2
into the string 123456
at the appropriate place (which isn't possible because there is no place designated for it).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…