Spaces:
Sleeping
Sleeping
import streamlit as st | |
# Title for Streamlit app | |
st.title("Temperature Conversion") | |
# Input temperature and conversion type | |
temperature = st.number_input("Enter Temperature:", value=0.0) | |
conversion_type = st.selectbox( | |
"Convert to:", | |
("Celsius to Fahrenheit", "Fahrenheit to Celsius", "Celsius to Kelvin", "Kelvin to Celsius", "Fahrenheit to Kelvin", "Kelvin to Fahrenheit") | |
) | |
# Perform temperature conversion | |
if st.button("Convert Temperature"): | |
if conversion_type == "Celsius to Fahrenheit": | |
converted_temp = (temperature * 9/5) + 32 | |
st.write(f"Temperature in Fahrenheit: {converted_temp:.2f} °F") | |
elif conversion_type == "Fahrenheit to Celsius": | |
converted_temp = (temperature - 32) * 5/9 | |
st.write(f"Temperature in Celsius: {converted_temp:.2f} °C") | |
elif conversion_type == "Celsius to Kelvin": | |
converted_temp = temperature + 273.15 | |
st.write(f"Temperature in Kelvin: {converted_temp:.2f} K") | |
elif conversion_type == "Kelvin to Celsius": | |
converted_temp = temperature - 273.15 | |
st.write(f"Temperature in Celsius: {converted_temp:.2f} °C") | |
elif conversion_type == "Fahrenheit to Kelvin": | |
converted_temp = (temperature - 32) * 5/9 + 273.15 | |
st.write(f"Temperature in Kelvin: {converted_temp:.2f} K") | |
elif conversion_type == "Kelvin to Fahrenheit": | |
converted_temp = (temperature - 273.15) * 9/5 + 32 | |
st.write(f"Temperature in Fahrenheit: {converted_temp:.2f} °F") | |
# Footer | |
st.markdown("---") | |
st.markdown( | |
"This app is designed for quick and easy temperature conversions using Streamlit." | |
) | |