Lectures

Tuesday I will talk about how you can control the behaviour of your program by asking the True/False questions we talked about last week. Apart from the "if" statement, there are a few others that will make your life as a programmer much easier. I will also talk about functions which are essentially the same as those you know from math. In programming — as in math — they form a convenient way to reuse functionality and to structure your code.

In the Thursday lecture I will talk more about control flow, boolean expressions and functions.

Computer exercises

For this weeks computer exercises, complete the Control flow and functions exercise and the Files and modules exercise.

Reading material

Apart from the pages I put up I recommend chapters two, three and four from 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

We will need to compute the square-root of some numbers. To do this we will use a function from the standard library. Type

from math import *

This will give you access to all the standard math functions. You can explore these by typing help(math). You will want the function called "sqrt". To get the square root of 4 type sqrt(4). Remember that to use this function in a module you will need to import the math module above the place where you attempt to use the function.

The actual assignment is a file containing the following functions:

If it works you should be able to call you functions and get these results:

>>> lengthOfHypotenuse(5, 4)
6.4031242374328485

>>> lengthOfLeg(5, 7)
4.8989794855663558

>>> lengthOfMissingSide(4, 5, 10)
6.4031242374328485

Handing in

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_week2.py. Attach it to an email with subject "Assignment" and send it to asand@cs.au.dk before 10am the following Wednesday.

Weekly evaluation

EvaluationWeek2

Index

Contact info

Office address:
Bioinformatics Research Centre (BiRC)
Aarhus University
C.F. Møllers Allé 8
DK-8000 Aarhus C
Denmark
Office phone:
+45 871 55558
Mobile phone:
3013 8342
Email:
kaspermunch@birc.au.dk