This site was recently migrated. Email any questions to daveagp@gmail.com.

15B: Python Pushups

Exercises 15A, 15B, and 15C can be completed in any order.

In this lesson, we give several medium-size exercises combining tools learned in earlier lessons.

In the next exercise, use the methods string.split(), which removes the spaces from a word and returns a list of the words it contains, and string.lower() which converts a string to lower case. For example,

"Split these words!".split() returns the list ["Split", "these", "words!"]

"LOWERCase".lower() returns "lowercase"

Note: split() can accept further options to split in other ways; see the documentation.

Suppose you have n flavours of ice cream, and want to make a sundae using exactly k of those flavours. How many different flavour combinations are possible? For example, if n=4 and k=2, there are 6 possibilities:

(1) A and B, (2) A and C, (3) A and D, (4) B and C, (5) B and D, (6) C and D.

(for example here the flavours are Apricot, Blueberry, Chocolate, and Date).

Similarly, you could be choosing 2 people out of 4 (Al, Bob, Carol, Di) to make a committee. How many ways can the committee be built? The answer would still be 6. The next problem is about computing this number.

In mathematics, the number you computed in the previous exercise is usually written

and called "n choose k." There are many interesting facts about these values such as

and

This is the end of our exercise session; you can move on to another lesson.