Learn / Python / Functions: a pressure unit converter
Python, lesson 5 of 6
Functions: a pressure unit converter
Functions turn a formula into a tool you can use again and again. They take inputs (parameters) and return a result:
def mm_to_inches(mm):
return round(mm / 25.4, 2)
print(mm_to_inches(100)) # 3.94
Engineers use converters like this every day. One megapascal (MPa) is 145.0377 psi.
Your turn
Write mpa_to_psi(mpa) that converts megapascals to psi (multiply by 145.0377) and rounds to 2 decimal places.
Press Run to see what your code prints.
Hint: return round(mpa * 145.0377, 2)