Print Final Statement Outside For Loop
<p>I'm trying to print a final statement that says "The 50th bus arrives at HH:MM." But it appears my print statement is still in my for loop. How do I get it out of it? Also, it seems like my output is still in brackets. I'm not sure how to get rid of that. Sorry, I'm very new to programming.</p>

<pre><code>import numpy as np
import math
import random

l=[]
for i in range (50):
    def nextTime(rateParameter):
        return -math.log(1.0 - random.random()) / rateParameter
    a = np.round(nextTime(1/15),0)
    l.append(a)
cum_l = np.cumsum(l)
print(cum_l)

print("The 50th bus arrives at ", cum_l//60,":", cum_l%60,2)
</code></pre>

<p><code>Print</code> is not in <code>for</code> loop. The reason you think that your <code>print</code> is in <code>for</code> loop is because you print <code>cum_l</code> which is a <code>list</code>. But you need only last element:</p>

<pre><code>import numpy as np
import math
import random

rateParameter = 1/15

def nextTime(rateParameter):
        return -math.log(1.0 - random.random()) / rateParameter

l=[]
for i in range (50):
    a = np.round(nextTime(rateParameter), 0)
    l.append(a)

cum_l = np.cumsum(l)
#print(cum_l)

output = ""
last = len(cum_l) - 1

output += str(cum_l[-1]//60) + ":" + str(cum_l[-1]%60)

print("The 50th bus arrives at: ", output)
</code></pre>

python python-3.x