Android Termux Script for complex Engineering Units
·1 min
Table of Contents
An advance engineering unit converter with special benefit in converting complex compounded units as shown in the video.
Try to organise scripts in adequately named folders
Steps required #
graph TD;
A[π± Get Android] --> B[π¦ Install Termux]
B --> C[π Install Python]
C --> D[βοΈ Install Python's Library]
D --> E[πββοΈ Run Script]
Calculator script #
import pint
## Initialize the unit registry
unt = pint.UnitRegistry(autoconvert_offset_to_baseunit=True, auto_reduce_dimensions=True)
print('Usage: quantity<space>fromUnit<space>toUnit', 'Type end to stop loop', sep='\n')
while True:
try:
tmp = input('Input quantity & units: ')
if tmp == 'end':
break
tmp = tmp.split()
if len(tmp) != 3:
raise ValueError("Input must be in the format: quantity fromUnit toUnit")
quantity = float(tmp[0])
from_unit = unt(tmp[1])
to_unit = unt(tmp[2])
result = (quantity * from_unit).to(to_unit)
print(result)
except ValueError as ve:
print(f"ValueError: {ve}")
except pint.UndefinedUnitError as ue:
print(f"UndefinedUnitError: {ue}")
except Exception as e:
print(f"An error occurred: {e}")
# Reset the input loop if an error occurs
print("Please try again.")