saherPervaiz commited on
Commit
21fdf01
·
verified ·
1 Parent(s): 079a7de

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Temperature conversion functions
4
+ def celsius_to_fahrenheit(celsius):
5
+ return (celsius * 9/5) + 32
6
+
7
+ def celsius_to_kelvin(celsius):
8
+ return celsius + 273.15
9
+
10
+ def fahrenheit_to_celsius(fahrenheit):
11
+ return (fahrenheit - 32) * 5/9
12
+
13
+ def fahrenheit_to_kelvin(fahrenheit):
14
+ return fahrenheit_to_celsius(fahrenheit) + 273.15
15
+
16
+ def kelvin_to_celsius(kelvin):
17
+ return kelvin - 273.15
18
+
19
+ def kelvin_to_fahrenheit(kelvin):
20
+ return celsius_to_fahrenheit(kelvin_to_celsius(kelvin))
21
+
22
+ # Streamlit app
23
+ st.title("Temperature Converter 🌡️")
24
+ st.subheader("Convert temperatures between Celsius, Fahrenheit, and Kelvin")
25
+
26
+ # Input for temperature and unit
27
+ temperature = st.number_input("Enter the temperature:", value=0.0)
28
+ unit = st.selectbox("Select the unit of the input temperature:", ["Celsius", "Fahrenheit", "Kelvin"])
29
+
30
+ # Conversion logic
31
+ if st.button("Convert"):
32
+ if unit == "Celsius":
33
+ fahrenheit = celsius_to_fahrenheit(temperature)
34
+ kelvin = celsius_to_kelvin(temperature)
35
+ st.write(f"**Fahrenheit:** {fahrenheit:.2f}°F")
36
+ st.write(f"**Kelvin:** {kelvin:.2f} K")
37
+ elif unit == "Fahrenheit":
38
+ celsius = fahrenheit_to_celsius(temperature)
39
+ kelvin = fahrenheit_to_kelvin(temperature)
40
+ st.write(f"**Celsius:** {celsius:.2f}°C")
41
+ st.write(f"**Kelvin:** {kelvin:.2f} K")
42
+ elif unit == "Kelvin":
43
+ celsius = kelvin_to_celsius(temperature)
44
+ fahrenheit = kelvin_to_fahrenheit(temperature)
45
+ st.write(f"**Celsius:** {celsius:.2f}°C")
46
+ st.write(f"**Fahrenheit:** {fahrenheit:.2f}°F")
47
+
48
+ st.write("Note: Ensure the input values are within valid ranges for temperature conversions.")