Hello.

Example: Delete all commas that appear before the first period. And replace with a plus all the numbers 3, which stand after the first point.

I wrote such a piece of code, I don’t know how to put a restriction further:

S = input(': ') S = S.replace('3', '+') S = S.replace(',', '') print(S) 

    3 answers 3

    You can use slices:

     s = 'a3a3a,b3b3.c3c3,d3d3d3.e3e3e3.' idx = s.index('.') res = s[:idx].replace(',','') + s[idx:].replace('3','+') print(res) 

    result:

     a3a3ab3b3.c+c+,d+d+d+.e+e+e+. 

      Delete all commas that appear before the first point ...
      Replace with a plus all the numbers 3, which stand after the first point.

       before_dot, dot, after_dot = input_text.partition('.') result = (before_dot.replace(',', '') + dot + after_dot.replace('3', '+')) 

      This continues to work for input that does not contain a point.

        Somehow it should be:

         tmp_str = S.split(".", 1) print(".".join([tmp_str[0].replace(",", ""), tmp_str[1].replace("3", "+")])) 
        • Thank you! And why does it remove the dot? - Vladislav
        • Fixed code - no longer deletes - it was just a copy-paste that was a bit of a curve - Axenow