import streamlit as st # Function to convert temperatures def convert_temperature(value, from_unit, to_unit): # Convert input to Celsius 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 # Convert Celsius to target unit 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 # Streamlit app layout st.title('Temperature Conversion App') st.write('Convert temperatures between Celsius, Fahrenheit, Kelvin, and Rankine.') # User input 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']) # Perform conversion 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}.')