Python Python Basics (2015) Logic in Python Try and Except

Maor Beeri
Maor Beeri
2,154 Points

I am not sure where to insert the try keyword here, need help

.

trial.py
def add(x,y):
    try:
        sum = (float(x) + float(y))
    except ValueError:
        return None
    else:
    return (float(x) + float(y))
Anthony Box
Anthony Box
7,435 Points

type checking. If x or y was a string or array, it couldn't be converted into a float therefore it needs to be handled. Extra... why calculate the sum again when it you've already stored the value?