KubraBashir's picture
Update app.py
1e13f60 verified
import streamlit as st
def convert_temperature(value, from_unit, to_unit):
if from_unit == to_unit:
return value
if 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
def main():
st.title("Temperature Conversion App")
st.write("Easily convert temperatures between Celsius, Fahrenheit, and Kelvin.")
# Input Section
value = st.number_input("Enter the temperature value:", format="%.2f")
from_unit = st.selectbox("Convert from:", ["Celsius", "Fahrenheit", "Kelvin"])
to_unit = st.selectbox("Convert to:", ["Celsius", "Fahrenheit", "Kelvin"])
# Convert Button
if st.button("Convert"):
result = convert_temperature(value, from_unit, to_unit)
st.success(f"{value} {from_unit} is equal to {result:.2f} {to_unit}")
if __name__ == "__main__":
main()