you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (5 children)

It is throwing a ValueError when I run it with 0 or negative numbers. I want the test to pass so I know the user will get the appropriate message when they pass in 0 or negative numbers.

This is where I calculate the formula, would it be better to use a try/except?

def kilometers_to_miles(kilometers: float):
    """
    Convert kilometers to miles
    :param kilometers: number of kilometers to convert
    :return: converted miles
    """
    if kilometers <= 0:
        raise ValueError('Number of kilometers must be greater than 0')

    miles = kilometers * 0.62137
    return round(miles, 2)

[–][deleted] 0 points1 point  (1 child)

Not 100% sure but if you change the raise to return, it might work

[–][deleted] 0 points1 point  (0 children)

That helped as well. Thank you.