import streamlit as st def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): return (fahrenheit - 32) * 5/9 # App layout st.title("🌡️ Temperature Converter") st.write("Convert temperatures between Celsius and Fahrenheit easily!") # Dropdown for conversion selection conversion_type = st.selectbox( "Select conversion type:", ("Celsius to Fahrenheit", "Fahrenheit to Celsius") ) # User input if conversion_type == "Celsius to Fahrenheit": celsius = st.number_input("Enter temperature in Celsius:", format="%.2f") if st.button("Convert"): fahrenheit = celsius_to_fahrenheit(celsius) st.success(f"{celsius}°C = {fahrenheit:.2f}°F") elif conversion_type == "Fahrenheit to Celsius": fahrenheit = st.number_input("Enter temperature in Fahrenheit:", format="%.2f") if st.button("Convert"): celsius = fahrenheit_to_celsius(fahrenheit) st.success(f"{fahrenheit}°F = {celsius:.2f}°C")