Reputation: 129
I am trying to use the result of the formula to compute the next result and then the next result after that and so on and so fourth.
def waiting(element, start_waiting_time=0, service_time=1.2, interarrival=1, default=0):
if element == 1:
return max((start_waiting_time + service_time - interarrival, 0))
elif element == 0:
return default
def waiting_time(elements, start_time=0):
next_patient_waits = start_time
for i in elements:
next_patient_waits += waiting(i)
print("{:.1f}".format(next_patient_waits))
elements = [1, 1, 1]
waiting_time(elements)
This code returns output:
# 0.2, 0.4, 0.6
I was expecting it to return output :
#0, 0.2, 0.4
I want to set the first waiting_time to 0 because the start_waiting_time is zero. I was hope the computer would compute:
#For 1st item in elements: waiting_time = 0
#For 2nd item in elements: waiting_time = (waiting time 1st element) + service_time - interarrival = 0 + 1.2 -1 = 0.2
#For 3rd item in elements: waiting_time = (waiting time 2nd element) + service_time - interarrival = 0.2 + 1.2 -1 = 0.4
Upvotes: 0
Views: 67
Reputation: 148890
You should simply print the next_patient_waits
before increasing it:
def waiting_time(elements, start_time=0):
next_patient_waits = start_time
for i in elements:
print("{:.1f}".format(next_patient_waits))
next_patient_waits += waiting(i)
Upvotes: 2