takewhile takes successive items from a sequence for as long as a certain condition is true.
It's the equivalent of using a _while_ loop to _take_ successive items from the sequence until the while condition is not met–hence the name takewhile.
2/7
In this example, the challenge is to see how many successive heads I can get when I flip a coin…
3/7
In the first attempt there's a list of heads and tails. In this one, there are three heads at the start of the list.
The result from takewhile gives three heads…
4/7
In the second part, we repeat this several times using a generator.
You can see the outputs range from some cases with no heads at all, and others with varying number of heads.
In recent years, I have introduced #Python#coding to chemists, biologists, psychologists, medical scientists, geologists, well, the list goes on.
Suffice to say that it spans all areas of science.
Why?
2/4
All of these teams and individuals realise that either they have large amounts of data they need to analyse in all sorts of different ways, or they need to simulate experiments and create computational models.
#Python is often the language of choice in many of these fields.
3/4
In this project, you'll get to use lists, tuples, dictionaries, and sets to set up the grid, colours, and get the balls to bounce and speed across the tiles.
It's fun to write, and fun to watch, too!
2 of 3
If you don't have the time for this but know someone who does, please do share…