Editor

Generate All Coin Flip Outcomes

Intermediate · Write the code · from Python itertools: Powerful Tools for Working with Iterables

From the lesson: Python itertools: Powerful Tools for Working with Iterables

Imagine you have a Swiss Army knife for loops. Instead of writing complicated nested loops and temporary lists, you pull out the right tiny tool and the job is done in one clean line.

Read the lesson

Use product to generate all possible outcomes of flipping a coin 3 times. The coin has sides 'H' and 'T'. Print each outcome tuple on its own line.

from itertools import product
# Generate and print all 3-flip outcomes

More itertools exercises

All Python exercises · 50 practice problems · Standard Library Essentials quiz