What is my mistake? My code: class RomanNumerals: @staticmethod def to_roman(val : int) -> str: otvet = '' while val>=1000: otvet += "M" val -= 1000 while val>= 900: otvet += "CM" val -= 900 while val>= 500: otvet += "D" val -= 500 while val >= 400: otvet += "CD" val -= 400 while val>= 100: otvet += "C" val -= 100 while val>= 90: otvet += "XC" val -= 90 while val>= 50: otvet += "L" val -= 50 while val>= 40: otvet += "XL" val -= 40 while val>= 10: otvet += "X" val -= 10 while val>= 9: otvet += "IX" val -= 9 while val>= 5: otvet += "V" val -= 5 while val>= 4: otvet += "IV" val -= 4 while val>= 1: otvet += "I" val -= 1 return otvet @staticmethod def from_roman(roman_num: str) -> int: otvet = 0 while 'CM' in roman_num: otvet += 900 roman_num = roman_num.replace('CM', '', 1) while 'CD' in roman_num: otvet += 400 roman_num = roman_num.replace('CD', '', 1) while 'XC' in roman_num: otvet += 90 roman_num = roman_num.replace('XC', '', 1) while 'XL' in roman_num: otvet += 40 roman_num = roman_num.replace('XL', '', 1) while 'IV' in roman_num: otvet += 4 roman_num = roman_num.replace('IV', '', 1) while 'M' in roman_num: otvet += 1000 roman_num = roman_num.replace('M', '', 1) while 'D' in roman_num: otvet += 500 roman_num = roman_num.replace('D', '', 1) while 'C' in roman_num: otvet += 100 roman_num = roman_num.replace('C', '', 1) while 'L' in roman_num: otvet += 50 roman_num = roman_num.replace('L', '', 1) while 'X' in roman_num: otvet += 10 roman_num = roman_num.replace('V', '', 1) while 'V' in roman_num: otvet += 5 roman_num = roman_num.replace('V', '', 1) while 'I' in roman_num: otvet += 1 roman_num = roman_num.replace('I', '', 1) return otvet print(RomanNumerals.to_roman(86 )) print(RomanNumerals.from_roman('XXI'))
You are not replacing the string correctly. You are replacing the first occurrence of the string, but you want to replace all occurrences. You can use the g flag to replace all occurrences: $('#myDiv').html($('#myDiv').html().replace(/(\<\/?)(div|p)/g, "$1clearfix$2"