Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialVladimir Lapcevic
6,363 PointsWhat is wrong with this code?
please help
musical_groups = [
["Ad Rock", "MCA", "Mike D."],
["John Lennon", "Paul McCartney", "Ringo Starr", "George Harrison"],
["Salt", "Peppa", "Spinderella"],
["Rivers Cuomo", "Patrick Wilson", "Brian Bell", "Scott Shriner"],
["Chuck D.", "Flavor Flav", "Professor Griff", "Khari Winn", "DJ Lord"],
["Axl Rose", "Slash", "Duff McKagan", "Steven Adler"],
["Run", "DMC", "Jam Master Jay"],
]
# Your code here
for group in musical_groups:
print(', '.join(group))
if len(group) == 3:
print(group)
2 Answers
Unsubscribed User
Front End Web Development Techdegree Student 33,900 PointsHi Vladimir,
in your code you already print out the result before the conditional statement runs...
But you want to only print it out IF the length of the group is 3.
So you just have to change the order of your code a bit.
Plus you don't need the second print command at the bottom of your code (you actually have two print commands).
Does that help?
PS: You can upvote my post and/or mark as "best answer" (at the bottom of my post) if it helped you. :-)
Drew Conner
4,027 PointsI think there is a misunderstanding in the phrasing of "Now I'd like to see only groups that are trios, you know 3 members. So can you please only print out the trios? It should still use the joined string format from task 1."
Instead of adding code to only print trios and still print all groups, you need to modify which groups are printed at all, as Nils mentioned.
If the expected output of task 2 is:
Ad Rock, MCA, Mike D.
Salt, Peppa, Spinderella
Run, DMC, Jam Master Jay
Can you think of a way to modify your code to produce that output?