File size: 1,270 Bytes
648435e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st

# Function to convert temperatures
def convert_temperature(value, from_unit, to_unit):
    # Convert input to Celsius
    if from_unit == 'Celsius':
        celsius = value
    elif from_unit == 'Fahrenheit':
        celsius = (value - 32) * 5/9
    elif from_unit == 'Kelvin':
        celsius = value - 273.15
    elif from_unit == 'Rankine':
        celsius = (value - 491.67) * 5/9

    # Convert Celsius to target unit
    if to_unit == 'Celsius':
        return celsius
    elif to_unit == 'Fahrenheit':
        return celsius * 9/5 + 32
    elif to_unit == 'Kelvin':
        return celsius + 273.15
    elif to_unit == 'Rankine':
        return (celsius + 273.15) * 9/5

# Streamlit app layout
st.title('Temperature Conversion App')
st.write('Convert temperatures between Celsius, Fahrenheit, Kelvin, and Rankine.')

# User input
value = st.number_input('Enter the temperature value:')
from_unit = st.selectbox('From unit:', ['Celsius', 'Fahrenheit', 'Kelvin', 'Rankine'])
to_unit = st.selectbox('To unit:', ['Celsius', 'Fahrenheit', 'Kelvin', 'Rankine'])

# Perform conversion
if st.button('Convert'):
    result = convert_temperature(value, from_unit, to_unit)
    st.write(f'{value}° {from_unit} is equal to {result:.2f}° {to_unit}.')