def reveal_num(line: str) -> int | float | None:
result =""
for char in line:
if char.isdigit():
result += char
elif char == '-' or char == '.' and not result:
result += char
if len(result)==0:
return None
elif result[0]=='-' or result[1]=='+':
return float(''.join(result[1::]))
else:
return float(''.join(result))
Created at: 2023/11/16 04:12; Updated at: 2023/11/17 10:18
The question is resolved.