My mission is to get a string from a user, and then:
- Change every
A
character in the list to digit 1 ("1"). - Change every
B
character in the list to digit 2 ("2"). - Change every
C
character in the list to digit 3 ("3").
That's what I've done until now:
string = input("Enter a string: ")
for i in range(len(string) - 1):
if string[i] == "A":
string[i] = "1"
elif string[i] == "B":
string[i] = "2"
elif string[i] == "C":
string[i] = "3"
But when I run it, the interpreter gives me this error:
line 4, in string[i] = "1" TypeError: 'str' object does not support item assignment
Does someone know how to make my code work?