File size: 1,625 Bytes
7333d79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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."
)