Shehroz-Ali-02's picture
Update app.py
30ca6c2 verified
import streamlit as st
def convert_temperature(value, from_unit, to_unit):
if from_unit == to_unit:
return value
elif from_unit == "Celsius" and to_unit == "Fahrenheit":
return (value * 9/5) + 32
elif from_unit == "Celsius" and to_unit == "Kelvin":
return value + 273.15
elif from_unit == "Fahrenheit" and to_unit == "Celsius":
return (value - 32) * 5/9
elif from_unit == "Fahrenheit" and to_unit == "Kelvin":
return (value - 32) * 5/9 + 273.15
elif from_unit == "Kelvin" and to_unit == "Celsius":
return value - 273.15
elif from_unit == "Kelvin" and to_unit == "Fahrenheit":
return (value - 273.15) * 9/5 + 32
st.set_page_config(page_title="Temperature Converter", page_icon="🌡️", layout="centered")
st.title("🌡️ Temperature Converter")
st.markdown("""
### Convert temperatures between Celsius, Fahrenheit, and Kelvin with ease.
""")
value = st.number_input("Enter Temperature:", format="%.2f")
from_unit = st.selectbox("From Unit", ["Celsius", "Fahrenheit", "Kelvin"])
to_unit = st.selectbox("To Unit", ["Celsius", "Fahrenheit", "Kelvin"])
if st.button("Convert"):
result = convert_temperature(value, from_unit, to_unit)
st.success(f"Converted Temperature: {result:.2f} {to_unit}")
st.markdown("""
**Instructions:**
- Enter the temperature value.
- Select the unit to convert from and the target unit.
- Click the **Convert** button to see the result.
""")
st.markdown("""
*Designed by ❤️ Shehroz Ali*
""")