Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple if else solution in Clear category for Reveal the Number by malion
def reveal_num(line):
dot = True
sign = ''
result = ''
for char in line:
if char == '.' and dot:
result += char
dot = False
elif char.isdigit():
result += char
elif char in ['-', '+'] and not result:
sign = char
return (float(sign + result) if '.' in result else int(sign + result)) \
if result else None
print("Example:")
print(reveal_num("+A%+-1-0..."))
# These "asserts" are used for self-checking
assert reveal_num("F0(t}") == 0
assert reveal_num("Utc&g") == None
assert reveal_num("-aB%|_-+2ADS.12+3.ADS1.2") == 2.12312
assert reveal_num("-aB%|_+-2ADS.12+3.ADS1.2") == -2.12312
assert reveal_num("zVâ„–1}3;o.vEf``C.WqTY0") == 13.0
assert reveal_num(
"!3B'j=(}89JQ6aWvN*%5@uy.r)B
Feb. 20, 2023
Comments: