Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Is there a way where I can add several names to if and elif,so it would be like elif/if first_name = "Alex" … and lets say 2 other names, how can plunge them in the same line,cause typical for now commas and + sign don't seem to add them.
Hi Alan, Not sure I understood your question, but here is something that might help you. You should use "or" in your function to add more than one name and not "+" So your code line should look like this:
elif first_name == "Alan" or "Antoine" or "Chris" : print... rest of your code
hopefully this helps !
Hey there Alan!
I am not sure what you mean by your question but check this out;
first_name = "Alan" last_name = "Temirov" full_name = "Alan Temirov" if first_name == "Alan" and last_name == "Temirov" or full_name == "Alan Temirov": print("Present") else: print("Absent")
Is this what you're looking for?
Thanks for the answer!But I was talking about how do I put more than 1 First names in the elif,when I type 3 names(not one as it was in the video) in the input line,it triggers the elifso it looks like this: elif first_name == "first_nameX" +"first_nameY" +"first_nameZ",but the + sign doesnt seem to do that,not does the comma,thats why Im confusesld
Patrick Townley3,472 Points
Some already suggested the straightforward approach:
if first_name == "Alex" or first_name == "Bob" or first_name == "Alice": print(first_name, "is one of the names I'm checking for!")
However, you can also check if the name is in a list of names - to me, this is easier to read:
if first_name in ["Alex","Bob","Alice"]: print(first_name, "is one of the names I'm checking for!")
You could even make that a variable defined earlier or elsewhere:
# Easier to add new names this way names_to_check = ["Alex", "Bob", "Alice"] if first_name in names_to_check: print(first_name, "is one of the names I'm checking for!")