Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time_duration_streamlit_app #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions time_duration_streamlit_app_testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import streamlit as st

# Define the add_time_durations function
def add_time_durations(time_str1, time_str2):
def convert_to_minutes(time_str):
value, unit = time_str.split()
if unit == "hours" or unit == "hour":
return int(value) * 60
elif unit == "minutes" or unit == "minute":
return int(value)
else:
raise ValueError(f"Unsupported time unit: {unit}")

minutes1 = convert_to_minutes(time_str1)
minutes2 = convert_to_minutes(time_str2)

total_minutes = minutes1 + minutes2
total_hours = total_minutes / 60
result_str = f'{total_hours:.1f} hours'

return result_str

# Streamlit app code
def main():
st.title("Time Duration Calculator")

time_str1 = st.text_input("Enter time duration in Hour(s)")
time_str2 = st.text_input("Enter time duration in minute(s)")

if st.button("Calculate"):
try:
result = add_time_durations(time_str1, time_str2)
st.success(f"The total time duration is: {result}")
except ValueError as e:
st.error(str(e))

if __name__ == "__main__":
main()


# In[ ]: