File size: 932 Bytes
c602f5a |
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 |
import streamlit as st
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
# Streamlit app
st.title("Temperature Converter")
# Selection
conversion_type = st.radio(
"Choose a conversion type:",
("Celsius to Fahrenheit", "Fahrenheit to Celsius")
)
# Input field
if conversion_type == "Celsius to Fahrenheit":
celsius = st.number_input("Enter temperature in Celsius:", format="%.2f")
if st.button("Convert"):
fahrenheit = celsius_to_fahrenheit(celsius)
st.success(f"{celsius:.2f} °C is equal to {fahrenheit:.2f} °F")
elif conversion_type == "Fahrenheit to Celsius":
fahrenheit = st.number_input("Enter temperature in Fahrenheit:", format="%.2f")
if st.button("Convert"):
celsius = fahrenheit_to_celsius(fahrenheit)
st.success(f"{fahrenheit:.2f} °F is equal to {celsius:.2f} °C")
|