Home

Additional practice

This additional practice is designed to facilitate the solving of several course assignments. The video lecture is aimed to facilitate the understanding of the concepts, not to introduce new ones.

Loops

  1. Simulate what will happen with the prey population in the absence of predators (initial population: 1000, increase of 5% a day, 200 days in total).
  2. In the presence of predator, the daily change in prey population (prey) will be:
    0.05*prey-0.0002*predator*prey
    Simulate the hypothetical case that the predator population does not change and is always 100. What will the prey population be after 10 days if it starts with 1000?

General loops

Here is a video lecture explaining a program with nested loops step by step. It does not contain more information than the book.

    1. Change the code in listing 23.3 in the book, so that it does not only print how many times heads are obtained 10 times in a row, but also how many times they are obtained 5 times and 20 times in a row, respectively.
    2. Change the code under a in such a way that random.randint is being used instead of random.choice.

  1. Print all combinations one can get if a coin is thrown five times (and where the order matters).

    1. Make a program that simulates the casting of two dice a hundred times.
    2. Adjust the program under a, so that it prints ‘2*6’ each time two sixes have been obtained.
    3. Adjust the program under b, so that it prints how many times two sixes have been obtained in total.

Proteomics

    1. Save the human brain protein file into the same folder that will contain your code. The following code prints each line in human_brain_proteins.csv. Alter the code in such a way that it prints all but the first line.
      inp = open('human_brain_proteins.csv')
      while True:
          s = inp.readline()
          print s
          if not s:
              break
      inp.close()
      
    2. What data type does s have?

  1. Create, based on the following string, a list which contains one word per element.
    s='The wheel is come full circle'
    

Dictionaries

Write a program that, starting from the reduced cdn dictionary defined below, generates a kind of inverse dictionary, where keys and values are interchanged. That is, it computes a new dictionary aacid, such that aacid['F phenylalanine'] gives the list ['ttt'] and so on.

cdn = {}
cdn['ttt'] = 'F phenylalanine'
cdn['tta'] = 'L leucine'
cdn['tct'] = 'S serine'
cdn['tat'] = 'Y tyrosine'
cdn['taa'] = ' '
cdn['tgt'] = 'C cysteine'
cdn['tgg'] = 'W tryptophan'
cdn['cct'] = 'P proline'
cdn['cat'] = 'H histidine'
cdn['caa'] = 'Q glutamine'
cdn['cgt'] = 'R arginine'
cdn['att'] = 'I isoleucine'
cdn['atg'] = 'M methionine'
cdn['act'] = 'T threonine'
cdn['aat'] = 'N asparagine'
cdn['aaa'] = 'K lysine'
cdn['agt'] = 'S serine'
cdn['gtt'] = 'V valine'
cdn['gct'] = 'A alanine'
cdn['gat'] = 'D aspartic acid'
cdn['gaa'] = 'E glutamic acid'
cdn['ggt'] = 'G glycine'

GenBank and FASTA

  1. Program a loop that prints the following output:
    1
    11
    21
    31
    41
    
  2. s='A stage where every man must play a part'
    
    1. Program a loop which prints this:
      A sta
      ge wh
      ere e
      very 
      man m
      ust p
      lay a
       part
      
      Hint: 'A sta' can be printed as follows
      print s[0:5]
      
    2. Alter the program, so that it prints this:
      A sta*
      ge wh*
      ere e*
      very *
      man m*
      ust p*
      lay a*
       part*
       
  3. Review the data types part of the first steps and find out how to format a number so that the last character is on the 10th position.
    Example:
             2
          4321
           354