May-23-2022, 09:43 PM
(This post was last modified: May-23-2022, 09:46 PM by Clunk_Head.)
(May-23-2022, 09:01 PM)bowlofred Wrote: Float will handle exponential notation while yours will not. Up to you if that's a problem. Yours will not handle negative numbers or numbers with an explicit plus sign.
Think I've got it fixed:
def is_number(string): if string.isnumeric(): return True if string[0] == '-' or string[0] == '+': return is_number(string[1: ]) if string.count('.') == 1: return is_number(string.replace('.', '') elif string.count('e') == 1: index = string.find('e') return is_number(string[ :index]) and is_number(string[index+1: ]) return FalseThere's probably another case that I've missed. Please let me know if you see one.