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
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).
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.
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.
Change the code under a in such a way that random.randint is being used instead of random.choice.
Print all combinations one can get if a coin is thrown five times (and where the order matters).
Make a program that simulates the casting of two dice a hundred
times.
Adjust the program under a, so that it prints ‘2*6’
each time two sixes have been obtained.
Adjust the program
under b, so that it prints how many times two sixes have been obtained
in total.
Proteomics
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()
What data type does s have?
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.