Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
def celsius_to_fahrenheit(celsius):
|
| 4 |
+
return (celsius * 9/5) + 32
|
| 5 |
+
|
| 6 |
+
def fahrenheit_to_celsius(fahrenheit):
|
| 7 |
+
return (fahrenheit - 32) * 5/9
|
| 8 |
+
|
| 9 |
+
# Streamlit app
|
| 10 |
+
st.title("Temperature Converter")
|
| 11 |
+
|
| 12 |
+
# Selection
|
| 13 |
+
conversion_type = st.radio(
|
| 14 |
+
"Choose a conversion type:",
|
| 15 |
+
("Celsius to Fahrenheit", "Fahrenheit to Celsius")
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# Input field
|
| 19 |
+
if conversion_type == "Celsius to Fahrenheit":
|
| 20 |
+
celsius = st.number_input("Enter temperature in Celsius:", format="%.2f")
|
| 21 |
+
if st.button("Convert"):
|
| 22 |
+
fahrenheit = celsius_to_fahrenheit(celsius)
|
| 23 |
+
st.success(f"{celsius:.2f} °C is equal to {fahrenheit:.2f} °F")
|
| 24 |
+
elif conversion_type == "Fahrenheit to Celsius":
|
| 25 |
+
fahrenheit = st.number_input("Enter temperature in Fahrenheit:", format="%.2f")
|
| 26 |
+
if st.button("Convert"):
|
| 27 |
+
celsius = fahrenheit_to_celsius(fahrenheit)
|
| 28 |
+
st.success(f"{fahrenheit:.2f} °F is equal to {celsius:.2f} °C")
|