async def convert(self, ctx, inputunit, outputunit): # the ctx parameter is short for 'context' """type your input and output units""" save = convert(inputunit, outputunit) await ctx.send("You are converting from " + inputunit + " to " + str(save) + " " + outputunit)
from unit_converter.converter import convert import pint import scipy.constants as cnst from molmass import Formula #simple conversion tool for one time conversion convert('60 m/s', 'km/h') #or we can use Pint! u = pint.UnitRegistry() Q = u.Quantity speed = Q(60, 'm/seconds') distance = Q(8, 'm') time = Q(15, 'seconds') speed = distance / time #print(speed.to('m/seconds')) speed = speed.to(u.km / u.hour) c = Q(cnst.c, 'm/s') lightyear = c * Q(1, 'year') print(lightyear.to('m')) #what is the density of NaCl if the a=0.563nm formulas_per_cell = 4 NaCl = Formula('NaCl') mass = formulas_per_cell * Q(NaCl.mass, 'g/mole') / Q(cnst.Avogadro, '1/mole') volume = Q(0.563, 'nm')**3 density = mass / volume print(density.to('grams/cm^3'))
def test_cases_tol_false(quantity, expected_value, desired_unit): result_value = convert(quantity, desired_unit) assert not result_value == expected_value
def test_cases(quantity, expected_value, desired_unit): result_value = convert(quantity, desired_unit) assert result_value == expected_value
def feetsToCentimeters(feets): return convert(str(feets)+'foot', 'cm')
def feetsToMeters(feets): return convert(str(feets)+'foot', 'm')
def feetsToInches(feets): return convert(str(feets)+'foot' 'inch')
def inchesToMeters(inches): return convert(str(inches)+'inch', 'm')
def inchesToCentimeters(inches): return convert(str(inches)+'inch', 'cm')
def inchesToFeets(inches): return convert(str(inches)+'inch', 'foot')