From bb970faa2b863fc4a8d60f10685e6f6ce6006549 Mon Sep 17 00:00:00 2001 From: Adrian Brealey Date: Mon, 5 Jan 2026 20:23:46 -0800 Subject: [PATCH 1/2] Add ounces to grams conversion. Adds a simple cooking-related unit conversion using the avoirdupois ounce. --- conversions/ounces_to_grams.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 conversions/ounces_to_grams.py diff --git a/conversions/ounces_to_grams.py b/conversions/ounces_to_grams.py new file mode 100644 index 000000000000..be49eaf6397b --- /dev/null +++ b/conversions/ounces_to_grams.py @@ -0,0 +1,24 @@ +""" +Convert ounces to grams. + +This conversion uses the avoirdupois ounce: +1 ounce = 28.3495 grams +""" + +def ounces_to_grams(ounces: float) -> float: + """ + Convert ounces to grams. + + :param ounces: Weight in ounces + :return: Weight in grams + """ + if ounces < 0: + raise ValueError("Weight cannot be negative") + + return ounces * 28.3495 + + +if __name__ == "__main__": + ounces = float(input("Enter weight in ounces: ")) + grams = ounces_to_grams(ounces) + print(f"{ounces} ounces is equal to {grams:.2f} grams") From 974e8a49253a66ca6af04a5e569b537c3aeafdcc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Jan 2026 04:34:23 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conversions/ounces_to_grams.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conversions/ounces_to_grams.py b/conversions/ounces_to_grams.py index be49eaf6397b..f40fba23fe79 100644 --- a/conversions/ounces_to_grams.py +++ b/conversions/ounces_to_grams.py @@ -5,6 +5,7 @@ 1 ounce = 28.3495 grams """ + def ounces_to_grams(ounces: float) -> float: """ Convert ounces to grams.