def ft_strToInt(src): if (src.isdigit()): nb = int(src) checkNumber(nb) return nb msg.printFail('Element "' + src + '" is not int') sys.exit(-1)
def checkNumber(nb): ''' check number if it's inf or nan ''' if nb == math.inf or nb == -math.inf or nb != nb: msg.printFail("This number is too large. I am not able to solve it.") sys.exit(-1)
def ft_strToFloat(src): tmp = src.replace('.', '', 1) if (tmp.find('.') == -1 and tmp.isdigit()): nb = float(src) checkNumber(nb) return nb msg.printFail('Element "' + src + '" is not float or int') sys.exit(-1)
def ft_division(a, b): ''' check if a or b is zero and return division or error ''' if b == 0: msg.printFail("Division by zero") sys.exit(-1) if a == 0: return 0 nb = a / b checkNumber(nb) return nb
def errorMessage(): msg.printFail('Unexpected syntax') sys.exit()