Editor

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 lesson

Given 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: 6
tops = ['shirt', 'sweater', 'hoodie']
bottoms = ['jeans', 'shorts']
# Print all combinations and the total count

More Nested Loops exercises

All Python exercises · 50 practice problems · Control Flow quiz