CoderHassan's picture
Rename app .py to app.py
146e6c8 verified
import streamlit as st
# Title and Description
st.title("Temperature Conversion App")
st.markdown("Convert temperatures between Celsius, Fahrenheit, and Kelvin.")
# Input Temperature
temp_input = st.number_input("Enter the temperature to convert:", format="%.2f")
# Conversion Option
conversion_type = st.radio(
"Select conversion type:",
(
"Celsius to Fahrenheit",
"Fahrenheit to Celsius",
"Celsius to Kelvin",
"Kelvin to Celsius",
"Fahrenheit to Kelvin",
"Kelvin to Fahrenheit",
),
)
# Conversion Logic
if conversion_type == "Celsius to Fahrenheit":
converted_temp = (temp_input * 9/5) + 32
st.write(f"{temp_input:.2f}°C is equal to {converted_temp:.2f}°F.")
elif conversion_type == "Fahrenheit to Celsius":
converted_temp = (temp_input - 32) * 5/9
st.write(f"{temp_input:.2f}°F is equal to {converted_temp:.2f}°C.")
elif conversion_type == "Celsius to Kelvin":
converted_temp = temp_input + 273.15
st.write(f"{temp_input:.2f}°C is equal to {converted_temp:.2f} K.")
elif conversion_type == "Kelvin to Celsius":
converted_temp = temp_input - 273.15
st.write(f"{temp_input:.2f} K is equal to {converted_temp:.2f}°C.")
elif conversion_type == "Fahrenheit to Kelvin":
converted_temp = (temp_input - 32) * 5/9 + 273.15
st.write(f"{temp_input:.2f}°F is equal to {converted_temp:.2f} K.")
elif conversion_type == "Kelvin to Fahrenheit":
converted_temp = (temp_input - 273.15) * 9/5 + 32
st.write(f"{temp_input:.2f} K is equal to {converted_temp:.2f}°F.")