ahsangahothi commited on
Commit
ea2f947
·
verified ·
1 Parent(s): bda44cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def convert_temperature(value, from_unit, to_unit):
4
+ """Convert temperature between Celsius, Fahrenheit, and Kelvin."""
5
+ if from_unit == "Celsius":
6
+ if to_unit == "Fahrenheit":
7
+ return (value * 9/5) + 32
8
+ elif to_unit == "Kelvin":
9
+ return value + 273.15
10
+ elif from_unit == "Fahrenheit":
11
+ if to_unit == "Celsius":
12
+ return (value - 32) * 5/9
13
+ elif to_unit == "Kelvin":
14
+ return (value - 32) * 5/9 + 273.15
15
+ elif from_unit == "Kelvin":
16
+ if to_unit == "Celsius":
17
+ return value - 273.15
18
+ elif to_unit == "Fahrenheit":
19
+ return (value - 273.15) * 9/5 + 32
20
+
21
+ def main():
22
+ st.title("Temperature Converter")
23
+
24
+ # User input: Temperature value
25
+ value = st.number_input("Enter temperature value:", min_value=-273.15)
26
+
27
+ # User input: Temperature units
28
+ from_unit = st.selectbox("Convert from:", ["Celsius", "Fahrenheit", "Kelvin"])
29
+ to_unit = st.selectbox("Convert to:", ["Celsius", "Fahrenheit", "Kelvin"])
30
+
31
+ # Convert and display result
32
+ if from_unit != to_unit:
33
+ converted_value = convert_temperature(value, from_unit, to_unit)
34
+ st.write(f"{value} {from_unit} is equal to {converted_value} {to_unit}.")
35
+ else:
36
+ st.write("Please choose different units to convert.")
37
+
38
+ if __name__ == "__main__":
39
+ main()