Lectures
This week we will look at classes and objects. We will also look at how to find bugs in your code.
Computer exercises
Complete the Trouble shooting exercise and the CodonBias exercise.
Reading material
Apart from the pages I put up I recommend
of How to Think Like a Computer Scientist. These chapters have more detail than what I will describe in the lectures so think of this material as an alternative source of learning that allows you to find more detail and see the topics explained in a different way.
Weekly assignment
Modify a dictionary
Write a function turnIntoFractions(d) that takes a dictionary d with integer values and replaces each value with the fraction of the total of all values. In other works, the function should not create and return a new dictionary. It must change the dictionary given as agument and return None. Hint: remember that the value of a dictionary variable is a reference.
census = {'men': 3942, 'women': 3517, 'eunuchs':1} turnIntoFractions(census) print censuswill print
{'eunuchs': 0.00013404825737265417, 'men': 0.5284182305630026, 'women': 0.4714477211796247}
Now say you have a list of tuples like this:
l = [(1, 2, False), (3, 8, True), (7,4, False)]
List comprehension
Write a list comphrehension that generates a list containing the square of the second element of the tuples where the third element is False. For the above case the resulting list would be:
[4, 16]
Remember to use square brackets, [ and ], for the list comprehension. If you use round brackets, ( and ), for the list comprehension the result is a generator object not a list object.
Formatted string
Write a single formatted string that when printed prints the following
This is a very easy exercise. It took me 6.3, minutes to complete.
using the following variables:
dificulty = "easy"
completedInSeconds = 376
To hand in the assignment put the code in a file named after your self and the week. If it was me it would be Kasper_Munch_week6.py. Attach it to an email with subject "Assignment" and send it to asand@cs.au.dk before 10am the following Wednesday.