All Outfit Combinations
Intermediate · Write the code · from Nested Loops: Patterns, Performance, and When to Avoid Them
From the lesson: Nested Loops: Patterns, Performance, and When to Avoid Them
Think about a spreadsheet. It has rows and columns. To read every cell, you go through each row, and for each row, you go through each column. That's two loops - one inside the other. That's a nested loop.
Read the lessonGiven a list of tops and bottoms, print every possible outfit combination followed by the total count.
Expected output:
shirt + jeans
shirt + shorts
sweater + jeans
sweater + shorts
hoodie + jeans
hoodie + shorts
Total outfits: 6tops = ['shirt', 'sweater', 'hoodie']
bottoms = ['jeans', 'shorts']
# Print all combinations and the total count
More Nested Loops exercises
- Print a RectangleBeginner
- Predict the OutputIntermediate
- Number TriangleIntermediate
- Sum All Grid ValuesIntermediate
- Fix the Coordinate GridIntermediate
All Python exercises · 50 practice problems · Control Flow quiz