Пример #1
0
    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)
Пример #2
0
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
Пример #5
0
def feetsToCentimeters(feets):
    return convert(str(feets)+'foot', 'cm')
Пример #6
0
def feetsToMeters(feets):
    return convert(str(feets)+'foot', 'm')
Пример #7
0
def feetsToInches(feets):
    return convert(str(feets)+'foot' 'inch')
Пример #8
0
def inchesToMeters(inches):
    return convert(str(inches)+'inch', 'm')
Пример #9
0
def inchesToCentimeters(inches):
    return convert(str(inches)+'inch', 'cm')
Пример #10
0
def inchesToFeets(inches):
    return convert(str(inches)+'inch', 'foot')