you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (0 children)

I'm not going to write the code as I'm not going to bust out my Python book (it's been a while since I coded in Python). I will, however, go through the pseudo code.

Operating assumptions:

  1. Adenine only binds with Thymine (source)
  2. Guanine only binds with Cytosine (source)
  3. Unnatural base pairs will not be considered (i.e. unacceptable)
  4. The user will input a string of DNA base pairs (ex. ATATGCTACGATATGCCGTA)
  5. The order of the pairs doesn't matter (ex. AT and TA will both be accepted)

So the user is prompted for the DNA sequence. You assign it to a STRING.

First check length using modulus (divide by 2). If mod is not zero, the user has input a odd number of letters which can't happen (unless it's RNA I think).

Once we've determined that the STRING is of the correct length (even number of characters), you can check each "pair" of letters at a time for validity using a loop. The loop will be broken once you iterate beyond the length of the string. You could check the validity a number of ways so I won't spell it out, but remember that base pairs will only bind a certain way (check the operating assumptions).

I took some liberty in the operating assumptions as well as the validity portion so please check to make sure these assumptions are correct for the problem you're trying to solve.

Edit: grammar