Is It In There? ๐
Python has a magic word for searching a list: in.
It answers a yes-or-no question โ "is this thing inside that list?" โ which
makes it perfect for an if:
squad = ["Ana", "Bo", "Cy"]
if "Bo" in squad:
print("Bo is here! ๐")
else:
print("No Bo today...")
You can search with a variable too:
visitor = "Cy"
if visitor in squad:
print("Come on in!")
It even works on strings โ if "z" in name: checks for a letter inside a word!
Your mission
Build a party door checker.
- Make a list called
guest_listwith at least 5 names - Make a variable called
visitorholding one name - Use
if/elsewithinto print whether they're welcome - Both messages should include the visitor's name (f-string time!)
Then try it: change visitor to someone NOT on the list and run again. ๐ช
Your code
Press โถ Run to see what your code does!