amasood commited on
Commit
503ebe7
·
verified ·
1 Parent(s): aea59b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -1,16 +1,42 @@
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
  st.title("Temperature Conversion App")
10
- st.write("Convert temperatures between Celsius and Fahrenheit.")
11
 
12
  # User input
13
- conversion_type = st.radio("Select conversion type:", ("Celsius to Fahrenheit", "Fahrenheit to Celsius"))
 
 
 
 
 
 
 
 
 
 
14
 
15
  temperature_input = st.number_input("Enter the temperature value:", format="%.2f")
16
 
@@ -18,6 +44,18 @@ temperature_input = st.number_input("Enter the temperature value:", format="%.2f
18
  if conversion_type == "Celsius to Fahrenheit":
19
  converted_temp = celsius_to_fahrenheit(temperature_input)
20
  st.write(f"{temperature_input}°C is equal to {converted_temp:.2f}°F.")
21
- else:
22
  converted_temp = fahrenheit_to_celsius(temperature_input)
23
  st.write(f"{temperature_input}°F is equal to {converted_temp:.2f}°C.")
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+ # Conversion functions
4
  def celsius_to_fahrenheit(celsius):
5
  return (celsius * 9/5) + 32
6
 
7
  def fahrenheit_to_celsius(fahrenheit):
8
  return (fahrenheit - 32) * 5/9
9
 
10
+ def celsius_to_kelvin(celsius):
11
+ return celsius + 273.15
12
+
13
+ def kelvin_to_celsius(kelvin):
14
+ return kelvin - 273.15
15
+
16
+ def fahrenheit_to_kelvin(fahrenheit):
17
+ celsius = fahrenheit_to_celsius(fahrenheit)
18
+ return celsius_to_kelvin(celsius)
19
+
20
+ def kelvin_to_fahrenheit(kelvin):
21
+ celsius = kelvin_to_celsius(kelvin)
22
+ return celsius_to_fahrenheit(celsius)
23
+
24
+ # Streamlit app
25
  st.title("Temperature Conversion App")
26
+ st.write("Convert temperatures between Celsius, Fahrenheit, and Kelvin.")
27
 
28
  # User input
29
+ conversion_type = st.selectbox(
30
+ "Select conversion type:",
31
+ (
32
+ "Celsius to Fahrenheit",
33
+ "Fahrenheit to Celsius",
34
+ "Celsius to Kelvin",
35
+ "Kelvin to Celsius",
36
+ "Fahrenheit to Kelvin",
37
+ "Kelvin to Fahrenheit"
38
+ )
39
+ )
40
 
41
  temperature_input = st.number_input("Enter the temperature value:", format="%.2f")
42
 
 
44
  if conversion_type == "Celsius to Fahrenheit":
45
  converted_temp = celsius_to_fahrenheit(temperature_input)
46
  st.write(f"{temperature_input}°C is equal to {converted_temp:.2f}°F.")
47
+ elif conversion_type == "Fahrenheit to Celsius":
48
  converted_temp = fahrenheit_to_celsius(temperature_input)
49
  st.write(f"{temperature_input}°F is equal to {converted_temp:.2f}°C.")
50
+ elif conversion_type == "Celsius to Kelvin":
51
+ converted_temp = celsius_to_kelvin(temperature_input)
52
+ st.write(f"{temperature_input}°C is equal to {converted_temp:.2f}K.")
53
+ elif conversion_type == "Kelvin to Celsius":
54
+ converted_temp = kelvin_to_celsius(temperature_input)
55
+ st.write(f"{temperature_input}K is equal to {converted_temp:.2f}°C.")
56
+ elif conversion_type == "Fahrenheit to Kelvin":
57
+ converted_temp = fahrenheit_to_kelvin(temperature_input)
58
+ st.write(f"{temperature_input}°F is equal to {converted_temp:.2f}K.")
59
+ elif conversion_type == "Kelvin to Fahrenheit":
60
+ converted_temp = kelvin_to_fahrenheit(temperature_input)
61
+ st.write(f"{temperature_input}K is equal to {converted_temp:.2f}°F.")