[PYTHON] I'll get rid of every single imperial system from the world!

Introduction

Have you ever had such an experience? No matter how many times I recalculate, I get only impossible results. When I gave up and submitted the assignment and listened to the commentary class, nothing happened, because the unit of length was ** yards **, so unit conversion was necessary for the calculation. The world is full of other units such as ** pounds, ounces, glen, feet, gallons, quarts .... **. If there is a surplus, romance, or at least make it a university unit. I shouted at the setting sun, clenching my helpless hands full of scratches, tossed by numerous units. "Imperial system ... I'll destroy it! From this world ... every one!"

Main story

Once again, hello. It's delicious. This time, it will be an introductory article of ** a library for calculation with units ** that converts units arbitrarily, created with the above motives. I hope you will use it as a task help tool! !! I'm glad to shed tears of tears when I raise a pull request or an issue. The demo that actually worked is here!

The code for github is here!

What was made

Installation method

pip install ChemNote  

How to use

We recommend running this library on jupyter notebook!

import ChemNote as cn  

Basic usage

x=cn.define(Numerical value,unit)  

Defined in. Can handle four arithmetic operations and exponentiation.

x.convertUnits({Old unit:(Coefficient when compatible,(New unit,New unitの次元)})  

Unit conversion with

x.show(Significant figures)  

Displayed as a formula with. However, on the jupyter notebook, on the last line

x

It is displayed as a mathematical formula just by saying.

print(x)  

Is displayed as tex text that is easy to copy. (If you enclose both ends with \ $, the formula will be displayed in the markdown cell.)

** The following sample is a demo when running on jupyter notebook. ** ** sample1

Let's calculate the weight of water in a cube with a side length of 10 inches.

l=cn.define(10,"inch")  
water=cn.define(1,{"g":1,"mL":-1})  
l**3*water  

1.639\times 10^{1}\, kg

sample2
If the container of sample1 weighs 1 pound, the total weight of the container and water is displayed in 2 significant figures.

m1=cn.define(100,"lb")  
m=l**3*water+m1  
m.show(2)  

6.17\times 10^{1}\, kg

sample3

It will remind you if you are adding or subtracting in different units.

m+l  

TypeError:units or their dimention are not same

sample4
If you want the exact number or want to copy it to another location as markdown, do the following:

float(m)  

61.746301

print(m)  

6.175\times 10^{1}, kg

At the end

I registered the library on pypi for the first time. I thought it would be nice to be able to publish what I made. I think that there are many points that can not be reached, so please comment etc. orz

Recommended Posts

I'll get rid of every single imperial system from the world!
Get the contents of git diff from python
[Python] Get the text of the law from the e-GOV Law API
Study from the beginning of Python Hour1: Hello World
Get rid of python's KeyError
Get the number of digits
Get rid of slow scp -pr
Get the number of views of Qiita
The world of control engineering books
Existence from the viewpoint of Python
Get the attributes of an object
Get the first element of queryset
Get the value from the [Django] Form
Get the number of Youtube subscribers
Get the address from the zip code
That's why I'll look up tweets from the House of Representatives election
Get the list of packages for the specified user from the packages registered on PyPI
Get the song name from the title of the video you tried to sing
Get the average salary of a job with specified conditions from indeed.com