This object may be implemented as a function, but it might have enough stuff to be it's own class. Basically, I need a way to handle conversions. The conversion object would take a float and a unit in its constructor:
def init(self, amount: float, unit: string)
The unit would be compared to const values currently implemented (tsp, t, tbsp, T, cup, C, cups. etc.). An error would be thrown if the units didn't exist. Once the amount and units are given, then the class would have a function that converts the amount based on the requested units. I imagine the class would be used like this:
M = Measure(3.0, 'tsp')
print(M)
_ '3.0 tsp'
M = M.convertto('tbsp')
print(M)
'1.0 tbsp'
This object may be implemented as a function, but it might have enough stuff to be it's own class. Basically, I need a way to handle conversions. The conversion object would take a float and a unit in its constructor:
def init(self, amount: float, unit: string)
The unit would be compared to const values currently implemented (tsp, t, tbsp, T, cup, C, cups. etc.). An error would be thrown if the units didn't exist. Once the amount and units are given, then the class would have a function that converts the amount based on the requested units. I imagine the class would be used like this:
M = Measure(3.0, 'tsp') print(M) _ '3.0 tsp' M = M.convertto('tbsp') print(M) '1.0 tbsp'