|
import streamlit as st |
|
|
|
|
|
def convert_temperature(value, from_unit, to_unit): |
|
|
|
if from_unit == 'Celsius': |
|
celsius = value |
|
elif from_unit == 'Fahrenheit': |
|
celsius = (value - 32) * 5/9 |
|
elif from_unit == 'Kelvin': |
|
celsius = value - 273.15 |
|
elif from_unit == 'Rankine': |
|
celsius = (value - 491.67) * 5/9 |
|
|
|
|
|
if to_unit == 'Celsius': |
|
return celsius |
|
elif to_unit == 'Fahrenheit': |
|
return celsius * 9/5 + 32 |
|
elif to_unit == 'Kelvin': |
|
return celsius + 273.15 |
|
elif to_unit == 'Rankine': |
|
return (celsius + 273.15) * 9/5 |
|
|
|
|
|
st.title('Temperature Conversion App') |
|
st.write('Convert temperatures between Celsius, Fahrenheit, Kelvin, and Rankine.') |
|
|
|
|
|
value = st.number_input('Enter the temperature value:') |
|
from_unit = st.selectbox('From unit:', ['Celsius', 'Fahrenheit', 'Kelvin', 'Rankine']) |
|
to_unit = st.selectbox('To unit:', ['Celsius', 'Fahrenheit', 'Kelvin', 'Rankine']) |
|
|
|
|
|
if st.button('Convert'): |
|
result = convert_temperature(value, from_unit, to_unit) |
|
st.write(f'{value}° {from_unit} is equal to {result:.2f}° {to_unit}.') |
|
|