title: Python : return True if ... else False statement (Boolean Value)
body: <blockquote>
    <p>Transitions between A &lt;-> G and C &lt;-> T<br>
    Transversions between A &lt;-> C and G &lt;-> T</p>
    
    <p>Assignment:  </p>
    
    <ul>
    <li>Write a function transition that takes two nucleotides. The function must return a Boolean value that indicates whether or not replacing the first nucleotide by the second nucleotide leads to a transition.</li>
    </ul>
  </blockquote>
  
  <p>Problem: I don't think the function recognizes the statement behind the <code>or</code>.
  The code doesn't work in some cases for example: <code>transition('A', 'G')</code> is True and with my code he gives False</p>
  
  <blockquote>
    <ul>
    <li>Write a function ratio that takes two DNA sequences s1 and s2<br>
    The function may assume that both sequences have the same length (the function does not need to check this explicitly). The function must return the transition/transversion ratio R(s 1 ,s 2 )∈R of the two given sequences as a floating point number. In case there are no transversions between the two sequences, R(s 1 ,s 2 )=0 by definition.</li>
    </ul>
  </blockquote>
  
  <p>Problem: the code is not working</p>
  
  <pre><code>def transition(letter1, letter2):        
      """
      &gt;&gt;&gt; transition('G', 'A')
      True
      &gt;&gt;&gt; transition('t', 'g')
      False
      &gt;&gt;&gt; transition('C', 'c')
      False
      """    
      return True if letter1.lower() == 'gt' and letter2.lower() == 'ac' or letter1.lower() == 'ac' and letter2.lower() == 'gt' else False
  
  
  def transversion(letter1, letter2):
      """
      &gt;&gt;&gt; transversion('G', 'A')
      False
      &gt;&gt;&gt; transversion('t', 'g')
      True
      &gt;&gt;&gt; transversion('C', 'c')
      False
      """
      return True if letter1.lower() == 'ct' and letter2.lower() == 'ag' or  letter1.lower() == 'ag' and letter2.lower() == 'ct' else False
  
  
  def ratio(seq1, seq2):
      """
      &gt;&gt;&gt; ratio('ATTAGCATTATCATC', 'AAATAGGATATATGG')
      0.2222222222222222
      &gt;&gt;&gt; seq1 = 'GCAACGCACAACGAAAACCCTTAGGGACTGGATTATTTCGTGATCGTTGTAGTTATTGGAAGTACGGGCATCAACCCAGTT'
      &gt;&gt;&gt; seq2 = 'ttatctgacaaagaaagccgtcaacggctggataatttcgcgatcgtgctggttactggcggtacgagtgttcctttgggt'
      &gt;&gt;&gt; ratio(seq1, seq2)   
      1.2142857142857142
      """
      count = 0
      tel = 0
  
      for i in range(len(seq1)):
          if transition(seq1[i], seq2[i]):
              count += 1
  
      for i in range(len(seq1)):
          if transversion(seq1[i], seq2[i]):
              tel += 1
  
      if tel != 0:
          return float(count / tel)
      else:
          return 0 
  
  if __name__ == '__main__':
      import doctest
      doctest.testmod()
  </code></pre>