Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
def convert_temperature(value, from_unit, to_unit):
|
3 |
+
if from_unit == to_unit:
|
4 |
+
return value
|
5 |
+
if from_unit == "Celsius" and to_unit == "Fahrenheit":
|
6 |
+
return value * 9 / 5 + 32
|
7 |
+
elif from_unit == "Celsius" and to_unit == "Kelvin":
|
8 |
+
return value + 273.15
|
9 |
+
elif from_unit == "Fahrenheit" and to_unit == "Celsius":
|
10 |
+
return (value - 32) * 5 / 9
|
11 |
+
elif from_unit == "Fahrenheit" and to_unit == "Kelvin":
|
12 |
+
return (value - 32) * 5 / 9 + 273.15
|
13 |
+
elif from_unit == "Kelvin" and to_unit == "Celsius":
|
14 |
+
return value - 273.15
|
15 |
+
elif from_unit == "Kelvin" and to_unit == "Fahrenheit":
|
16 |
+
return (value - 273.15) * 9 / 5 + 32
|
17 |
+
|
18 |
+
def main():
|
19 |
+
st.title("Temperature Conversion App")
|
20 |
+
st.write("Easily convert temperatures between Celsius, Fahrenheit, and Kelvin.")
|
21 |
+
|
22 |
+
# Input Section
|
23 |
+
value = st.number_input("Enter the temperature value:", format="%.2f")
|
24 |
+
from_unit = st.selectbox("Convert from:", ["Celsius", "Fahrenheit", "Kelvin"])
|
25 |
+
to_unit = st.selectbox("Convert to:", ["Celsius", "Fahrenheit", "Kelvin"])
|
26 |
+
|
27 |
+
# Convert Button
|
28 |
+
if st.button("Convert"):
|
29 |
+
result = convert_temperature(value, from_unit, to_unit)
|
30 |
+
st.success(f"{value} {from_unit} is equal to {result:.2f} {to_unit}")
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
main()
|