0
0
Pythonprogramming~15 mins

Nested for loop execution in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested for loop execution
📖 Scenario: You are organizing a small event and want to create a seating chart. You have a list of tables and a list of guests. You want to pair each guest with each table to see all possible seating options.
🎯 Goal: Build a program that uses nested for loops to print every combination of tables and guests.
📋 What You'll Learn
Create a list called tables with the values 'Table 1', 'Table 2', and 'Table 3'
Create a list called guests with the values 'Alice', 'Bob', and 'Charlie'
Use a nested for loop with variables table and guest to iterate over tables and guests
Print each combination in the format: Guest Alice sits at Table 1
💡 Why This Matters
🌍 Real World
Event planners often need to consider all seating options to organize guests efficiently.
💼 Career
Understanding nested loops is essential for tasks like scheduling, pairing data, and generating combinations in programming jobs.
Progress0 / 4 steps
1
Create the tables list
Create a list called tables with these exact values: 'Table 1', 'Table 2', and 'Table 3'
Python
Need a hint?

Use square brackets [] to create a list and separate items with commas.

2
Create the guests list
Create a list called guests with these exact values: 'Alice', 'Bob', and 'Charlie'
Python
Need a hint?

Use the same list syntax as before to create the guests list.

3
Write the nested for loops
Use nested for loops with variables table and guest to iterate over tables and guests respectively
Python
Need a hint?

Write one for loop inside another. The inner loop goes through guests.

4
Print each seating combination
Inside the nested loops, write a print statement to display: Guest {guest} sits at {table} using an f-string
Python
Need a hint?

Use print(f"Guest {guest} sits at {table}") inside the inner loop.