def round_ans(val, decimals=2): """ Rounds the value to a specified number of decimal places. :param val: Number to be rounded :param decimals: Number of decimal places to round to (default is 1) :return: Rounded value as a string """ return f"{val:.{decimals}f}" def to_grams(to_convert): """ Converts from Oz to G :param to_convert: Weight to be converted in Oz :return: Converted Weight in G or error if negative value """ if to_convert < 0: return "Error: Weight cannot be negative" answer = to_convert * 28.35 return round_ans(answer) def to_ounces(to_convert): """ Converts from G to Oz :param to_convert: Weight to be converted in G :return: Converted Weight in Oz or error if negative value """ if to_convert < 0: return "Error: Weight cannot be negative" answer = to_convert / 28.35 return round_ans(answer) # Main routine / Testing starts here if __name__ == "__main__": # Test Cases for Conversion Functions print("10 Oz to Grams:", to_grams(10)) # Converts 10 Oz to Grams print("100 Grams to Ounces:", to_ounces(100)) # Converts 100 Grams to Ounces print("Invalid Test (Negative Value -5 Oz):", to_grams(-5)) # Should return an error message print("Invalid Test (Negative Value -100g):", to_ounces(-100)) # Should return an error message