The assignment is:
Your task is correcting the errors in the digitized text. You only have to handle the following mistakes:
- S is misinterpreted as 5
- O is misinterpreted as 0
- I is misinterpreted as 1
My code:
def correct(string):
for i in string:
if '5' in string:
string = string.replace('5','S')
elif '0' in string:
string = string.replace('0','O')
elif '1' in string:
string = string.replace('1','I')
return string
I know this solution will not work for a word like:
Test.assert_equals(correct("51NGAP0RE"),"SINGAPORE");
Does anyone have tips on how to make this a more general function that will work for every word?