There was an error while loading. Please reload this page.
1 parent 3c88735 commit bb970faCopy full SHA for bb970fa
1 file changed
conversions/ounces_to_grams.py
@@ -0,0 +1,24 @@
1
+"""
2
+Convert ounces to grams.
3
+
4
+This conversion uses the avoirdupois ounce:
5
+1 ounce = 28.3495 grams
6
7
8
+def ounces_to_grams(ounces: float) -> float:
9
+ """
10
+ Convert ounces to grams.
11
12
+ :param ounces: Weight in ounces
13
+ :return: Weight in grams
14
15
+ if ounces < 0:
16
+ raise ValueError("Weight cannot be negative")
17
18
+ return ounces * 28.3495
19
20
21
+if __name__ == "__main__":
22
+ ounces = float(input("Enter weight in ounces: "))
23
+ grams = ounces_to_grams(ounces)
24
+ print(f"{ounces} ounces is equal to {grams:.2f} grams")
0 commit comments