-1

TypeError: 'str' object does not support item assignment

I am taking a 11 digit number as input in recieved_code, later on after getting the error position, I want to replace that digit with 0 or 1 depending on the condition.

recieved_code = (input())

#Detecting the position of error

parList = parList[: : -1]
error = 0
for i in range(0,len(parList)):
    error = error + pow(2,i)*parList[i]
print("\nError is at position:",error)

#Correcting the error
if recieved_code[error-1] == 1:
    print("It's 1")
    recieved_code[error-1] = 0
else:
    print("It's 0")
    recieved_code[error-1] = 1

print("Corrected code:",recieved_code)

I wanted 0 to be replaced by 1, or 1 to be replaced by 0.

This is the error

1

1 Answer 1

1

Strings are immutable

That means that once created, you can't modify the string itself. You need to create another one after processing/concatenating/etc...

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please give me the solution

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.