Unitconverter

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

print("This a unit converter program")

print("mass units \npound=lbm, kilogram=kg, \nlength units\nfeet=ft, metre=m ")

print("Pressure units\nPascal=Pa, atmospheric Pressure= atm, millimeter of mercury=mm of Hg, Torr =


Torr, Bar = bar ")

print("energy units \nBritish Thermal unit=Btu, Joule=J, calorie=cal")

print("Power units \nWatt=W, horse power=hp, Kilowatthour=Kwh")

num1 = input('Enter the value: ')

unit1 = input('Which unit do you want it converted from: ')


unit2 = input('Which unit do you want it converted to: ')

if unit1 == "kg" and unit2 == "lbm":


ans = float(num1) / 0.4539
print(ans, "lbm")
elif unit1 == "lbm" and unit2 == "kg":
ans = 0.45359 * float(num1)
print(ans, " Kg")

elif unit1 == "ft" and unit2 == "m":


ans = 0.3048 * float(num1)
print(ans, "m")
elif unit1 == "m" and unit2 == "ft":
ans = float(num1) / 0.3048
print(ans, "ft")

elif unit1 == "Btu" and unit2 == "J":


ans = 1055.1 * float(num1)
print(ans, "J")
elif unit1 == "cal" and unit2 == "J":
ans = 4.1868 * float(num1)
print(ans, "J")
elif unit1 == "J" and unit2 == "cal":
ans = float(num1)/4.1868
print(ans, "cal")
elif unit1 == "J" and unit2 == "Btu":
ans = float(num1) / 1055.1
print(ans, "Btu")

elif unit1 == "W" and unit2 == "J/s":


ans = float(num1)
print(ans, "J/s \nsince 1 W = 1 J/s")
elif unit1 == "J/s" and unit2 == "W":
ans = float(num1)
print(ans, "W \n1 W= 1 J/s")
elif unit1 == "hp" and unit2 == "W":
ans = 746 * float(num1)
print(ans,"W")
elif unit1 == "W" and unit2 == "hp":
ans = float(num1) / 746
print(ans,"hp")

elif unit1 == "Kwh" and unit2 == "J":


ans = 3600000 * float(num1)
print(ans,"J")
elif unit1 == "J" and unit2 == "Kwh":
ans = float(num1) / 3600000
print(ans,"Kwh")

elif unit1 == "Pa" and unit2 == "N/m2":


ans = float(num1)
print(ans,"N/m2 \n1 Pa = 1 N/m2")
elif unit1 == "N/m2" and unit2 == "Pa":
ans = float(num1)
print(ans,"Pa \n1 Pa = 1 N/m2")
elif unit1 == "atm" and unit2 == "mm of Hg":
ans = float(num1) * 760
print(ans,"mm of Hg")
elif unit1 == "mm of hg" and unit2 == "atm":
ans = float(num1) / 760
print(ans,"atm")
elif unit1 == "atm" and unit2 == "N/m2":
ans = float(num1) * 101325
print(ans,"N/m2")
elif unit1 == "N/m2" and unit2 == "atm":
ans = float(num1) / 101325
print(ans,"atm")
elif unit1 == "Torr" and unit2 == "mm of Hg":
ans = float(num1)
print(ans,"mm of Hg \n1 mm of Hg = 1 Torr")
elif unit1 == "mm of Hg" and unit2 == "Torr":
ans = float(num1)
print(ans,"Torr \n1 mm of Hg = 1 Torr")
elif unit1 == "atm" and unit2 == "Torr":
ans = float(num1) * 760
print(ans,"Torr")
elif unit1 == "Torr" and unit2 == "atm":
ans = float(num1) / 760
print(ans,"atm")
elif unit1 == "bar" and unit2 == "Pa":
ans = float(num1) * 100000
print(ans,"Pa")
elif unit1 == "Pa" and unit2 == "bar":
ans = float(num1) / 100000
print(ans,"bar")
else:
print("type correct units as mentioned above ")

You might also like