Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Creative but slow solution in Creative category for Is String a Number? by Marco_Monti
def is_number(val: str) -> bool:
if isinstance(val, int):
return True
else:
if val == "":
return False
numbers = "0123456789"
for i in val:
if not i in numbers:
return False
return True
print("Example:")
print(is_number("34"))
# These "asserts" are used for self-checking
assert is_number("34") == True
assert is_number("df") == False
assert is_number("") == False
assert is_number("a5") == False
assert is_number("ITS A NUMBER") == False
assert is_number("5a") == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 9, 2022
Comments: