Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Currency Style by m.kleinkranenbarg
import re
CURRENCY = re.compile(r'(\$[0-9,.]*[0-9])')
FLOATING_POINT = re.compile(r'(.*)[,.]([0-9][0-9])$')
def checkio(line: str) -> str:
def convert(matchobj):
return re.sub(FLOATING_POINT, r'\1fp\2',
matchobj.group(0)).replace('.', ',').replace('fp', '.')
return re.sub(CURRENCY, convert, line)
print("Example:")
print(checkio("$5.34"))
assert checkio("$5.34") == "$5.34"
assert checkio("$5,34") == "$5.34"
assert checkio("$222,100,455.34") == "$222,100,455.34"
assert checkio("Is $1.050,25 bigger than $1,050?") == "Is $1,050.25 bigger than $1,050?"
assert checkio("$222.100.455,34") == "$222,100,455.34"
assert checkio("$222,100,455") == "$222,100,455"
assert checkio("222.100.455") == "222.100.455"
assert (
checkio("This is an IP address 192.168.1.1") == "This is an IP address 192.168.1.1"
)
assert checkio("The price of bread is $1,50") == "The price of bread is $1.50"
assert (
checkio("The price of bread is 1,50 in some currency.")
== "The price of bread is 1,50 in some currency."
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 25, 2023