File size: 1,571 Bytes
510595a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
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.")