Light Mode
Dark Mode
I don't understand why it doesn't work :(.
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: Nov. 16, 2023, 4:12 a.m.
Updated: Nov. 17, 2023, 10:18 a.m.
0
13
User avatar
msibirov1975