In [1]:
%matplotlib inline

Lab00: Simple Python exercises

1. Make a list of the numbers 1 to 10.

2. Make a list of the first 10 square numbers.

3. Make a list of the first 10 square numbers in reversed order.

4. Repeat 3 but only keep the square numbers divisible by 4.

5. A Pythagoran triple is a tuple of 3 positive integers (a, b, c) such that \(a^2 + b^2 =c ^2\). Find the unique Pythagorean triples where c is less than 20.

In [8]:
dna = """
TTTAAATTCCCTGGCACCCGCTGGAGTTCTCGATTTCGAC
CAACCACGACGGTGTGATTCTGAATGTAGTTAGTATCTAC
CCAGAGCTCAGGTCATATCGCGCCAAGCATAAAGGTGGCT
GTTGAAAGTCGATGTCCGTATAAGTTCCGTTTCCTAATGA
"""

6. Remove any blank space characters including newlines in dna.

7. Find the unique bases in dna.

8. Find the position of the first occrurence of ‘C’ in dna.

9. Find the position of the second occurrence of ‘G’ in dna.

10. What is the sequence of the complementary strand of DNA? Recall from grade school biology that A is complementary to T and C is complementary to G.

11. Can you print the complemntary DNA strand with only 40 characters to a line

Using regular Python

Using bash magic

12. A 1-D random walk experiment starts from value 0, then either adds or subtracts 1 at each step. Run \(n\) such random walks, each time recording the final value after \(k\) steps. Show the counts of eac final value. What is the mean and standard deviaiton of the final values?

Let \(n\) = 10000 and \(k=100\). Use the standard libary package random to generate random steps.