Shahabmoin commited on
Commit
3c8f4c4
·
verified ·
1 Parent(s): 33d8a73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py CHANGED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Conversion factors for various time units
4
+ TIME_UNITS = {
5
+ 'Seconds': 1,
6
+ 'Minutes': 60,
7
+ 'Hours': 3600,
8
+ 'Days': 86400,
9
+ 'Weeks': 604800,
10
+ 'Months (30 days)': 2592000,
11
+ 'Years (365 days)': 31536000
12
+ }
13
+
14
+ def convert_time(value, from_unit, to_unit):
15
+ # Convert the input value to seconds
16
+ value_in_seconds = value * TIME_UNITS[from_unit]
17
+
18
+ # Convert from seconds to the target unit
19
+ converted_value = value_in_seconds / TIME_UNITS[to_unit]
20
+
21
+ return converted_value
22
+
23
+ def main():
24
+ st.title('Time Units Converter')
25
+
26
+ # Input value and select time units
27
+ value = st.number_input("Enter the value to convert", min_value=0.0, step=0.1)
28
+
29
+ from_unit = st.selectbox("From unit", list(TIME_UNITS.keys()))
30
+ to_unit = st.selectbox("To unit", list(TIME_UNITS.keys()))
31
+
32
+ if st.button('Convert'):
33
+ if value >= 0:
34
+ converted_value = convert_time(value, from_unit, to_unit)
35
+ st.write(f"{value} {from_unit} = {converted_value:.4f} {to_unit}")
36
+ else:
37
+ st.error("Please enter a valid value (greater than or equal to 0).")
38
+
39
+ if __name__ == "__main__":
40
+ main()