Using string or list operations detect the last two characters which will be unit of the quantity.
Like this
run this code, it will detect unit from the entered figure
This is the output
It does not detect abbreviations for 'micro'(μ),'ohm'(Ω) etc.. you can add them and form a character map
After extracting the unit from the entered figure write a program to convert it to a target unit based on SI standards.
Like this
Code
import string
figure = raw_input('enter a figure with its unit: ')
unit = ''
for letter in figure:
if letter in string.ascii_letters:
unit += letter
print unitrun this code, it will detect unit from the entered figure
This is the output
Code
>>>
enter a figure with its unit: 1.5mV
mV
>>>It does not detect abbreviations for 'micro'(μ),'ohm'(Ω) etc.. you can add them and form a character map
After extracting the unit from the entered figure write a program to convert it to a target unit based on SI standards.
