Mar-21-2019, 04:30 PM
I am making a calculator which calculates distance/speed/velocity with different kinds of units. No problems with the maths itself, but something wrong with the code. it shows TypeError: unsupported operand type(s) for /: 'float' and 'NoneType' (line 7). I tried converting everything what I can to floats, but it keeps popping up. I would appreciate your help very much, thanks!
def calculate(unit_time, unit_distance, unit_speed, time, distance, velocity): speed_units = {"km/S": 0.001, "km/min": 0.06, "m/S": 1, "km/h": 3.6, "dm/S": 10, "cm/S": 100, "mm/S": 1000, "dm/min": 600, "cm/min": 6000, "dm/h": 36000, "mm/min": 60000, "cm/h": 360000, "mm/h": 3600000} time_units = {"S": 1, "min": 60, "h": 3600} distance_units = {"mm": 0.001, "cm": 0.01, "dm": 0.1, "m": 1, "km": 1000} if velocity == "x": result = distance / time / (time_units.get(unit_time) / distance_units.get(unit_distance) / speed_units.get(unit_speed)) return result if distance == "x": result = velocity * time / (distance_units.get(unit_distance) / (time_units.get(unit_time) / speed_units.get(unit_speed))) return result if time == "x": result = distance / velocity / (time_units.get(unit_time) / distance_units.get(unit_distance) / speed_units.get(unit_speed)) return result print(calculate("min", "m", "cm/km", 12.0, 13.0, "x"))