def convert_to_float(frac_str):
try:
return float(frac_str)
except ValueError:
num, denom = frac_str.split('/')
try:
leading, num = num.split(' ')
whole = float(leading)
except ValueError:
whole = 0
frac = float(num) / float(denom)
return whole - frac if whole < 0 else whole + frac
print convert_to_float('3')
print convert_to_float('3/2')
print convert_to_float('1 1/2')
print convert_to_float('-1 1/2')
ZGVmIGNvbnZlcnRfdG9fZmxvYXQoZnJhY19zdHIpOgogICAgdHJ5OgogICAgICAgIHJldHVybiBmbG9hdChmcmFjX3N0cikKICAgIGV4Y2VwdCBWYWx1ZUVycm9yOgogICAgICAgIG51bSwgZGVub20gPSBmcmFjX3N0ci5zcGxpdCgnLycpCiAgICAgICAgdHJ5OgogICAgICAgICAgICBsZWFkaW5nLCBudW0gPSBudW0uc3BsaXQoJyAnKQogICAgICAgICAgICB3aG9sZSA9IGZsb2F0KGxlYWRpbmcpCiAgICAgICAgZXhjZXB0IFZhbHVlRXJyb3I6CiAgICAgICAgCXdob2xlID0gMAogICAgICAgIGZyYWMgPSBmbG9hdChudW0pIC8gZmxvYXQoZGVub20pCiAgICAgICAgcmV0dXJuIHdob2xlIC0gZnJhYyBpZiB3aG9sZSA8IDAgZWxzZSB3aG9sZSArIGZyYWMKICAgICAgICAKICAgICAgICAKcHJpbnQgY29udmVydF90b19mbG9hdCgnMycpCnByaW50IGNvbnZlcnRfdG9fZmxvYXQoJzMvMicpCnByaW50IGNvbnZlcnRfdG9fZmxvYXQoJzEgMS8yJykKcHJpbnQgY29udmVydF90b19mbG9hdCgnLTEgMS8yJyk=