import streamlit as st # Conversion functions def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): return (fahrenheit - 32) * 5/9 def celsius_to_kelvin(celsius): return celsius + 273.15 def kelvin_to_celsius(kelvin): return kelvin - 273.15 def fahrenheit_to_kelvin(fahrenheit): celsius = fahrenheit_to_celsius(fahrenheit) return celsius_to_kelvin(celsius) def kelvin_to_fahrenheit(kelvin): celsius = kelvin_to_celsius(kelvin) return celsius_to_fahrenheit(celsius) # Streamlit app st.set_page_config( page_title="Temperature Converter", page_icon="🌡️", layout="centered" ) # App title with icon st.markdown( "

🌡️ Temperature Conversion App

", unsafe_allow_html=True ) st.write("Convert temperatures between Celsius, Fahrenheit, and Kelvin with ease!") # Sidebar for user input st.sidebar.header("Conversion Options") conversion_type = st.sidebar.radio( "Choose a conversion type:", ( "Celsius to Fahrenheit", "Fahrenheit to Celsius", "Celsius to Kelvin", "Kelvin to Celsius", "Fahrenheit to Kelvin", "Kelvin to Fahrenheit" ) ) st.sidebar.markdown( "
", unsafe_allow_html=True ) temperature_input = st.sidebar.number_input( "Enter the temperature value:", format="%.2f" ) # Add a button for conversion if st.sidebar.button("Convert"): if conversion_type == "Celsius to Fahrenheit": converted_temp = celsius_to_fahrenheit(temperature_input) result = f"{temperature_input}°C is equal to {converted_temp:.2f}°F." elif conversion_type == "Fahrenheit to Celsius": converted_temp = fahrenheit_to_celsius(temperature_input) result = f"{temperature_input}°F is equal to {converted_temp:.2f}°C." elif conversion_type == "Celsius to Kelvin": converted_temp = celsius_to_kelvin(temperature_input) result = f"{temperature_input}°C is equal to {converted_temp:.2f}K." elif conversion_type == "Kelvin to Celsius": converted_temp = kelvin_to_celsius(temperature_input) result = f"{temperature_input}K is equal to {converted_temp:.2f}°C." elif conversion_type == "Fahrenheit to Kelvin": converted_temp = fahrenheit_to_kelvin(temperature_input) result = f"{temperature_input}°F is equal to {converted_temp:.2f}K." elif conversion_type == "Kelvin to Fahrenheit": converted_temp = kelvin_to_fahrenheit(temperature_input) result = f"{temperature_input}K is equal to {converted_temp:.2f}°F." # Display result with styled text st.markdown( f"

{result}

", unsafe_allow_html=True ) # Footer st.markdown( "
", unsafe_allow_html=True ) st.markdown( "

Made with ❤️ using Streamlit

", unsafe_allow_html=True )