Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to derive the number of days from a division

I have a data that gives me the number of days waiting in a year i.e 8 days waiting in a particular year. I have broken down this down to a specific hours in a day….say, 0.0312 hr/day.

I have a function that looks like this:

data = {a:24}
for k, v in data.items():
   if v/24 <= 1:
     wait_time = 0.0312
   else:....

I have an issue with the else statement. The if condition says that if the time in the data dictionary is less than or equal to 1 day, then wait time should be 0.0312 hr, otherwise, wait time should be 0.0312 * the number of days. The issue here is how to specify the number of days.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Ideally, I would want the number of days to be derived from v/24 division. For instance I want the following

if v/24 > 1 <= 2; then 0.0312 * 2
if v/24 > 2 <= 3; then 0.0312 * 3
if v/24 > 3 <= 4; then 0.0312 * 4

I want this for up to 365 days. Anyone has an idea of how to go about this? Thanks.

>Solution :

This should work for your condition

import math

data = {'a': 25}  # example data: 24 hours waiting in a year

for k, v in data.items():
    if v/24 <= 1:
        wait_time = 0.0312  # fixed wait time for less than or equal to 1 day
    else:
        num_days = math.ceil(v/24)  # calculate number of days rounded up to nearest integer
        wait_time = 0.0312 * num_days
    print(f"{k}: {wait_time}")

The result will be : –

a: 0.0624

hope it helps.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading