SamiKhokhar commited on
Commit
ebeb38c
·
verified ·
1 Parent(s): 6bde716

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def convert_temperature(value, from_unit, to_unit):
4
+ if from_unit == "Celsius" and to_unit == "Fahrenheit":
5
+ return value * 9/5 + 32
6
+ elif from_unit == "Celsius" and to_unit == "Kelvin":
7
+ return value + 273.15
8
+ elif from_unit == "Fahrenheit" and to_unit == "Celsius":
9
+ return (value - 32) * 5/9
10
+ elif from_unit == "Fahrenheit" and to_unit == "Kelvin":
11
+ return (value - 32) * 5/9 + 273.15
12
+ elif from_unit == "Kelvin" and to_unit == "Celsius":
13
+ return value - 273.15
14
+ elif from_unit == "Kelvin" and to_unit == "Fahrenheit":
15
+ return (value - 273.15) * 9/5 + 32
16
+ else:
17
+ return value # Same unit, no conversion
18
+
19
+ def main():
20
+ st.title("Temperature Conversion App")
21
+
22
+ st.sidebar.header("Input Temperature")
23
+ temperature = st.sidebar.number_input("Enter the temperature value:", value=0.0)
24
+ from_unit = st.sidebar.selectbox("From unit:", ["Celsius", "Fahrenheit", "Kelvin"])
25
+ to_unit = st.sidebar.selectbox("To unit:", ["Celsius", "Fahrenheit", "Kelvin"])
26
+
27
+ if st.sidebar.button("Convert"):
28
+ result = convert_temperature(temperature, from_unit, to_unit)
29
+ st.success(f"{temperature} {from_unit} = {result:.2f} {to_unit}")
30
+
31
+ st.sidebar.write("Developed by [Your Name]")
32
+
33
+ if __name__ == "__main__":
34
+ main()