Skip to content Skip to sidebar Skip to footer

Typeerror: Not All Arguments Converted During String Formatting

I have a program that's supposed to calculate Hamming Code for even parity with a 7-bit integer, here is the program: data=list(input('Enter a 7-bit binary integer:')) if (data[0]

Solution 1:

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).

Post a Comment for "Typeerror: Not All Arguments Converted During String Formatting"