adnaniqbal001 commited on
Commit
58508a4
·
verified ·
1 Parent(s): 53046f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def celsius_to_fahrenheit(celsius):
4
+ return (celsius * 9/5) + 32
5
+
6
+ def fahrenheit_to_celsius(fahrenheit):
7
+ return (fahrenheit - 32) * 5/9
8
+
9
+ # App layout
10
+ st.title("🌡️ Temperature Converter")
11
+ st.write("Convert temperatures between Celsius and Fahrenheit easily!")
12
+
13
+ # Dropdown for conversion selection
14
+ conversion_type = st.selectbox(
15
+ "Select conversion type:",
16
+ ("Celsius to Fahrenheit", "Fahrenheit to Celsius")
17
+ )
18
+
19
+ # User input
20
+ if conversion_type == "Celsius to Fahrenheit":
21
+ celsius = st.number_input("Enter temperature in Celsius:", format="%.2f")
22
+ if st.button("Convert"):
23
+ fahrenheit = celsius_to_fahrenheit(celsius)
24
+ st.success(f"{celsius}°C = {fahrenheit:.2f}°F")
25
+ elif conversion_type == "Fahrenheit to Celsius":
26
+ fahrenheit = st.number_input("Enter temperature in Fahrenheit:", format="%.2f")
27
+ if st.button("Convert"):
28
+ celsius = fahrenheit_to_celsius(fahrenheit)
29
+ st.success(f"{fahrenheit}°F = {celsius:.2f}°C")