title: How to process the data returned from a function (Python 3.7)
body: <p>Background:
  My question should be relatively easy, however I am not able to figure it out. 
  I have written a function regarding queueing theory and it will be used for ambulance service planning. For example, how many calls for service can I expect in a given time frame. 
  The function takes two parameters; a starting value of the number of ambulances in my system starting at 0 and ending at 100 ambulances. This will show the probability of zero calls for service, one call for service, three calls for service….up to 100 calls for service. Second parameter is an arrival rate number which is the past historical arrival rate in my system. 
  The function runs and prints out the result to my screen. I have checked the math and it appears to be correct. </p>
  
  <p>This is Python 3.7 with the Anaconda distribution. </p>
  
  <p>My question is this:
  I would like to process this data even further but I don’t know how to capture it and do more math. For example, I would like to take this list and accumulate the probability values. With an arrival rate of five, there is a cumulative probability of 61.56% of at least five calls for service, etc. </p>
  
  <p>A second example of how I would like to process this data is to format it as percentages and write out a text file </p>
  
  <p>A third example would be to process the cumulative probabilities and exclude any values higher than the 99% cumulative value (because these vanish into extremely small numbers). </p>
  
  <p>A fourth example would be to create a bar chart showing the probability of n calls for service.</p>
  
  <p>These are some of the things I want to do with the queueing theory calculations. And there are a lot more. I am planning on writing a larger application. But I am stuck at this point. The function writes an output into my Python 3.7 console. How do I “capture” that output as an object or something and perform other processing on  the data?</p>
  
  <pre><code>#!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  import math
  import csv
  
  def probability_x(start_value = 0, arrival_rate = 0):
      probability_arrivals = []
      while start_value  &lt;= 100:
          probability_arrivals = [start_value, math.pow(arrival_rate, start_value) * math.pow(math.e, -arrival_rate) / math.factorial(start_value)]
          print(probability_arrivals)
          start_value = start_value + 1
      return probability_arrivals
  
  #probability_x(arrival_rate = 5, x = 5)
  
  #The code written above prints to the console, but my goal is to take the returned values and make other calculations. 
  #How do I 'capture' this data for further processing is where I need help (for example, bar plots, cumulative frequency, etc )
  
  #failure. TypeError: writerows() argument must be iterable. 
  with open('ExpectedProbability.csv', 'w') as writeFile:
      writer = csv.writer(writeFile)
      for value in probability_x(arrival_rate = 5):
          writer.writerows(value)
  writeFile.close()
  
  #Failure. Why does it return 2. Yes there are two columns but I was expecting 101 as the length because that is the end of my loop.
  print(len(probability_x(arrival_rate = 5)))
  </code></pre>