0
0
Pythonprogramming~15 mins

List length and membership test in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
List length and membership test
๐Ÿ“– Scenario: You are organizing a small party and have a list of guests who have confirmed their attendance.You want to check how many guests are coming and whether a special friend is on the list.
๐ŸŽฏ Goal: Create a list of guests, count how many guests are coming, check if a special friend is attending, and print the results.
๐Ÿ“‹ What You'll Learn
Create a list called guests with the exact names: 'Alice', 'Bob', 'Charlie', 'Diana'
Create a variable called special_friend and set it to 'Charlie'
Create a variable called guest_count that stores the length of the guests list
Create a variable called is_special_friend_coming that checks if special_friend is in the guests list
Print the number of guests and whether the special friend is coming exactly as shown
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Managing guest lists for events or parties is a common task. Knowing how to count attendees and check if important people are coming helps with planning.
๐Ÿ’ผ Career
This teaches basic list handling and condition checking, foundational skills for data processing, user management, and many programming jobs.
Progress0 / 4 steps
1
Create the guest list
Create a list called guests with these exact names: 'Alice', 'Bob', 'Charlie', 'Diana'
Python
Need a hint?

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

2
Set the special friend
Create a variable called special_friend and set it to the string 'Charlie'
Python
Need a hint?

Use an equals sign = to assign the string 'Charlie' to special_friend.

3
Count guests and check membership
Create a variable called guest_count that stores the length of the guests list using the len() function. Then create a variable called is_special_friend_coming that checks if special_friend is in the guests list using the in keyword.
Python
Need a hint?

Use len(guests) to get the number of guests. Use special_friend in guests to check if the friend is coming.

4
Print the results
Print the number of guests using print(f"Number of guests: {guest_count}") and print whether the special friend is coming using print(f"Is special friend coming? {is_special_friend_coming}")
Python
Need a hint?

Use print() with f-strings to show the results clearly.