Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Title for Streamlit app
|
4 |
+
st.title("Temperature Conversion")
|
5 |
+
|
6 |
+
# Input temperature and conversion type
|
7 |
+
temperature = st.number_input("Enter Temperature:", value=0.0)
|
8 |
+
conversion_type = st.selectbox(
|
9 |
+
"Convert to:",
|
10 |
+
("Celsius to Fahrenheit", "Fahrenheit to Celsius", "Celsius to Kelvin", "Kelvin to Celsius", "Fahrenheit to Kelvin", "Kelvin to Fahrenheit")
|
11 |
+
)
|
12 |
+
|
13 |
+
# Perform temperature conversion
|
14 |
+
if st.button("Convert Temperature"):
|
15 |
+
if conversion_type == "Celsius to Fahrenheit":
|
16 |
+
converted_temp = (temperature * 9/5) + 32
|
17 |
+
st.write(f"Temperature in Fahrenheit: {converted_temp:.2f} °F")
|
18 |
+
elif conversion_type == "Fahrenheit to Celsius":
|
19 |
+
converted_temp = (temperature - 32) * 5/9
|
20 |
+
st.write(f"Temperature in Celsius: {converted_temp:.2f} °C")
|
21 |
+
elif conversion_type == "Celsius to Kelvin":
|
22 |
+
converted_temp = temperature + 273.15
|
23 |
+
st.write(f"Temperature in Kelvin: {converted_temp:.2f} K")
|
24 |
+
elif conversion_type == "Kelvin to Celsius":
|
25 |
+
converted_temp = temperature - 273.15
|
26 |
+
st.write(f"Temperature in Celsius: {converted_temp:.2f} °C")
|
27 |
+
elif conversion_type == "Fahrenheit to Kelvin":
|
28 |
+
converted_temp = (temperature - 32) * 5/9 + 273.15
|
29 |
+
st.write(f"Temperature in Kelvin: {converted_temp:.2f} K")
|
30 |
+
elif conversion_type == "Kelvin to Fahrenheit":
|
31 |
+
converted_temp = (temperature - 273.15) * 9/5 + 32
|
32 |
+
st.write(f"Temperature in Fahrenheit: {converted_temp:.2f} °F")
|
33 |
+
|
34 |
+
# Footer
|
35 |
+
st.markdown("---")
|
36 |
+
st.markdown(
|
37 |
+
"This app is designed for quick and easy temperature conversions using Streamlit."
|
38 |
+
)
|