Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Joke solution in Creative category for Is String a Number? (Part II) by Pavellver
def is_number(val: str) -> bool:
a = None
try:
a = eval(val)
except:
SyntaxError
return not val.startswith('--') if a and 'e' not in val else False
print("Example:")
print(is_number("10"))
# These "asserts" are used for self-checking
assert is_number("34") == True
assert is_number("df") == False
assert is_number("") == False
assert is_number("+10.0") == True
assert is_number("1OOO") == False
assert is_number("1.") == True
assert is_number("+.l") == False
assert is_number("++1+.2-") == False
assert is_number("3e4") == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 21, 2023
Comments: