title: TypeError: '<' not supported between instances of 'float' and 'function'
body: <p>I am trying to create a very simple virus-cure simulation. I created two files (infection.py and medicine.py), one simulating a virus and one simulating a very simplified cure. The first program works perfectly fine on its own. It is returning a list containing the amount of viruses for each time unit. The second program has the first program imported and is supossed to create some kind of cure. I mostly use predefined functions from program 1, and I redefined <code>simulate()</code>. </p>
  
  <p>To understand this program: 'The Cure' starts after <code>timestep = 100</code>, this is after the virus has been diagnosed. The virus can only reproduce if it is resistant to the cure, in other words, if the virus contains 'AAA'. A virus can die, reproduce and mutate. A mutation can sometimes result in resistancy.</p>
  
  <p>Everything should be working (in theory?), however I get the same error message over and over again when running program 2: <code>TypeError: '&lt;' not supported between instances of 'float' and 'function'</code>. I know what it means, but it says the error comes from a function predefined in program 1. But program 1 has no difficulty running this function whatsoever. I tried storing the value of <code>random.random()</code> and then using it, but this did not work. This is my code:</p>
  
  <p>PROGRAM 1</p>
  
  <pre><code>import random
  
  def generateVirus(length):
      return ''.join([random.choice(['A', 'G', 'T', 'C']) for i in range(length)])
  
  def mutate(virus):
      rand = random.randint(0, len(virus)-1)
      return virus[:rand] + random.choice([i for i in 'AGTC' if i != virus[rand]]) + virus[rand+1:]
  
  def kill(viruses, mortalityProb):
      return [survivors for survivors in viruses if random.random() &gt; mortalityProb]
  
  def reproduce(viruses, mutationProb, reproductionProb):
      nextgen = []
      for i in viruses:
          nextgen.append(i)
          if random.random() &lt; reproductionProb:
              if random.random() &lt; mutationProb:
                  nextgen.append(mutate(i))
              else:
                  nextgen.append(i)
      return nextgen
  
  def reproductionProbability(viruses, maxReproductionProb, maxPopulation):
      return (1 - (len(viruses) / maxPopulation)) * maxReproductionProb
  
  def simulate(viruses, mortalityProb, mutationProb, maxReproductionProb, 
      maxPopulation, timesteps = 500):
      pop_size = []
      while timesteps &gt; -1:
          survivors = kill(viruses, mortalityProb)
          reproductionProb = reproductionProbability(survivors, maxReproductionProb, maxPopulation)
          viruses = reproduce(survivors, mutationProb, reproductionProb)
          pop_size.append(len(viruses))
          timesteps -= 1
      return pop_size
  
  print(simulate(['GCTCC', 'CCGG', 'AACCGG', 'CCCTATAGG'], 0.05, 0.1, 0.07, 1000))
  </code></pre>
  
  <p>PROGRAM 2</p>
  
  <pre><code>import infection
  
  def isResistent(virus):
      if virus.find('AAA') &gt; -1:
          return True
      else:
          return False
  
  def simulate(viruses, mortalityProb, mutationProb, maxReproductionProb, maxPopulation, timesteps = 500):
      activation_cure = 400
      while timesteps &gt; -1:
          survivors = infection.kill(viruses, mortalityProb)
          for virus in viruses:
              if timesteps &lt; activation_cure and isResistent(virus):
                  reproductionProb = infection.reproductionProbability
                  infection.reproduce(viruses, mutationProb, reproductionProb)
          timesteps -= 1
      return len(viruses)
  
  def experiment(numberOfPatients):
      cured = 0
      viruses = []
      for i in range(10):
          viruses.append(infection.generateVirus(16))
      for i in range(numberOfPatients):
          remaining_virus = simulate(viruses, 0.05, 0.1, 0.07, 1000)
          if remaining_virus[len(remaining_virus)-1] == 0:
              cured += 1
      return cured
  
  print(experiment(5))
  </code></pre>
  
  <p>COMPLETE ERROR MESSAGE</p>
  
  <pre><code>File "C:\something\workspace\infection.py", line 17, in reproduce
  if random.random() &lt; reproductionProb:
  TypeError: '&lt;' not supported between instances of 'float' and 'function'
  </code></pre>