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.
>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.