[Tutor] Character Buffer Object Error
pasokan at talentsprint.com
Wed Feb 8 07:51:31 CET 2012
Overall I see a few problems.
0. Functions should return values. Not print them
1. Why use enumerate? The code is not using the index anyway
2. The following line appears wrong.
new_output = ' '.join(user_input)
3. This line has a very buggy possibility.
Let us say you have 234. First time you will replace 2 with 3, getting 334.
And then you will replace the first 3 with 4 getting 434 and finally
end up with 534. Of course due to other coding errors this does not
come to pass. But your basic idea of using str.replace() is prone
to this problem.
4. How are you supposed to treat 9?
Anyway back to your problem:
> I want to find all digits in a string and then increment those digits by 1
> and then return the same string with the incremented digits.
Initialise and outstring (empty)
Read the instring character by character
if the current character is not a digit
append it to outstring
append the transform(current char) to outstring
If you can organize your code like this it may be easier
More information about the Tutor