<div dir="ltr">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.<div><br></div><div>I've tried the following code, but I am getting the following error. How do I do this properly?</div>
<div><br></div><div><div>def AlterInput(user_input):</div><div> print user_input</div><div> new_output = ''</div><div> for index, char in enumerate(user_input):</div><div> if char.isdigit():</div>
<div>
new_char = int(char)</div><div> new_char += 1</div><div> new_output = ' '.join(user_input)</div><div> new_output.replace(char, new_char) </div><div> print new_output</div>
<div><br></div><div>def GetUserInput():</div><div> '''Get a string from the user and pass it'''</div><div> user_input = '''I got 432 when I counted, but Jim got 433 which</div><div>
is a lot for only 6 cats, or were there 12 cats?'''</div><div> AlterInput(user_input.split())</div><div><br></div><div><br></div><div><div>Traceback (most recent call last):</div><div> File "C:/Python27/Homework/Homework 4_1.py", line 25, in <module></div>
<div> GetUserInput()</div><div> File "C:/Python27/Homework/Homework 4_1.py", line 23, in GetUserInput</div><div> AlterInput(user_input.split())</div><div> File "C:/Python27/Homework/Homework 4_1.py", line 15, in AlterInput</div>
<div> new_output.replace(char, new_char)</div><div>TypeError: expected a character buffer object</div></div><br>
</div><div>Thanks.</div></div>