MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / weight_conversion

Function weight_conversion

conversions/weight_conversion.py:62–313  ·  view source on GitHub ↗

Conversion of weight unit with the help of KILOGRAM_CHART "kilogram" : 1, "gram" : pow(10, 3), "milligram" : pow(10, 6), "metric-ton" : pow(10, -3), "long-ton" : 0.0009842073, "short-ton" : 0.0011023122, "pound" : 2.2046244202, "stone": 0.1574731728, "ounce"

(from_type: str, to_type: str, value: float)

Source from the content-addressed store, hash-verified

60
61
62def weight_conversion(from_type: str, to_type: str, value: float) -> float:
63 """
64 Conversion of weight unit with the help of KILOGRAM_CHART
65
66 "kilogram" : 1,
67 "gram" : pow(10, 3),
68 "milligram" : pow(10, 6),
69 "metric-ton" : pow(10, -3),
70 "long-ton" : 0.0009842073,
71 "short-ton" : 0.0011023122,
72 "pound" : 2.2046244202,
73 "stone": 0.1574731728,
74 "ounce" : 35.273990723,
75 "carrat" : 5000,
76 "atomic-mass-unit" : 6.022136652E+26
77
78 >>> weight_conversion("kilogram","kilogram",4)
79 4
80 >>> weight_conversion("kilogram","gram",1)
81 1000
82 >>> weight_conversion("kilogram","milligram",4)
83 4000000
84 >>> weight_conversion("kilogram","metric-ton",4)
85 0.004
86 >>> weight_conversion("kilogram","long-ton",3)
87 0.0029526219
88 >>> weight_conversion("kilogram","short-ton",1)
89 0.0011023122
90 >>> weight_conversion("kilogram","pound",4)
91 8.8184976808
92 >>> weight_conversion("kilogram","stone",5)
93 0.7873658640000001
94 >>> weight_conversion("kilogram","ounce",4)
95 141.095962892
96 >>> weight_conversion("kilogram","carrat",3)
97 15000
98 >>> weight_conversion("kilogram","atomic-mass-unit",1)
99 6.022136652e+26
100 >>> weight_conversion("gram","kilogram",1)
101 0.001
102 >>> weight_conversion("gram","gram",3)
103 3.0
104 >>> weight_conversion("gram","milligram",2)
105 2000.0
106 >>> weight_conversion("gram","metric-ton",4)
107 4e-06
108 >>> weight_conversion("gram","long-ton",3)
109 2.9526219e-06
110 >>> weight_conversion("gram","short-ton",3)
111 3.3069366000000003e-06
112 >>> weight_conversion("gram","pound",3)
113 0.0066138732606
114 >>> weight_conversion("gram","stone",4)
115 0.0006298926912000001
116 >>> weight_conversion("gram","ounce",1)
117 0.035273990723
118 >>> weight_conversion("gram","carrat",2)
119 10.0

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected