import streamlit as st # Function to convert temperatures def convert_temperature(value, from_unit, to_unit): if from_unit == 'Celsius': if to_unit == 'Fahrenheit': return (value * 9/5) + 32 elif to_unit == 'Kelvin': return value + 273.15 elif from_unit == 'Fahrenheit': if to_unit == 'Celsius': return (value - 32) * 5/9 elif to_unit == 'Kelvin': return ((value - 32) * 5/9) + 273.15 elif from_unit == 'Kelvin': if to_unit == 'Celsius': return value - 273.15 elif to_unit == 'Fahrenheit': return ((value - 273.15) * 9/5) + 32 return value # Streamlit app layout st.title("Temperature Converter") # Input temperature value temp_value = st.number_input("Enter temperature value", step=0.1) # Select units for conversion from_unit = st.selectbox("From", ["Celsius", "Fahrenheit", "Kelvin"]) to_unit = st.selectbox("To", ["Celsius", "Fahrenheit", "Kelvin"]) # Convert button if st.button("Convert"): converted_value = convert_temperature(temp_value, from_unit, to_unit) st.write(f"{temp_value} {from_unit} is equal to {converted_value:.2f} {to_unit}")