-1

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.

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.

Babz
  • 15
  • 4
  • 2
    Why not `v * 24 / 365`? – mousetail Apr 11 '23 at 12:13
  • 48 * 24 / 365 = 3.16, which is greater than 2 days. – Babz Apr 11 '23 at 12:26
  • Is there any particular significance to the number .0312, or is it just an example? (I thought at first it might be 1/365, but that's .0027.) – CrazyChucky Apr 11 '23 at 12:26
  • @Babz No, that's 3.16 hours a day which is what you wanted. This comes out to 24 days a year – mousetail Apr 11 '23 at 12:28
  • 2
    .0312 is a fixed number of waiting hours per day. I want multiply this number by the number of days derived from v/24 division. For instance if v = 25 hours, then v/24 is 1.04, which is greater than 1 day. since this is greater than 1 day, I want .0312 * 2.... where 2 is 2days. – Babz Apr 11 '23 at 12:31
  • Are you familiar with [`math.ceil`](https://docs.python.org/3/library/math.html#math.ceil)? – CrazyChucky Apr 11 '23 at 12:32
  • No, would read through to see how it works. – Babz Apr 11 '23 at 12:34
  • I think this answers your question: https://stackoverflow.com/questions/2356501/how-do-you-round-up-a-number – CrazyChucky Apr 11 '23 at 12:35

1 Answers1

0

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.

sdave
  • 531
  • 4
  • 18