My Python code, it got accetped.
class Solution(object): def isNumber(self, s): """ :type s: str :rtype: bool """ try: isinstance(float(s), float) if True: return True else: return False except ValueError: return False
Feels a bit "cheaty", to be honest. I see the purpose of this task to implement the checking function yourself, not to ask interpreter to try and do that for you. This would be superior version for production, though.
BTW, your code can be made shorter:
try: float(s) return True except ValueError: return False
This would be accepted as well.