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 trialjemazar
3,258 PointsAssertionError in Challenge group 2/2 python
When i run my code on the workspace i get the output i want. When in challenge mode i get a pass on the first test and a fail on the second. Im really clueless what todo here.
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"],
]
for members in musical_groups:
string = ', '.join(members)
for members in musical_groups:
if len(members) == 3:
print(members)
1 Answer
Steven Parker
231,248 PointsHere's a couple of hints:
- you'll need only one loop, in task 2 you will add to the task 1 loop
- in task 2 you will still print the same joined list, only now it will be controlled by an "if" statement
jemazar
3,258 PointsI tried to improve it with the clues you gave me Steven Parker, Only 1 loop and the if statement. I passs the first test , fail the second.
for member in musical_groups: members = len(member) ( ', ').join(member) if members == 3: print(member)
jemazar
3,258 Pointsfor member in musical_groups: members = len(member) ( ', ').join(member) if members == 3: print(member)
Steven Parker
231,248 PointsWithout Markdown formatting it's hard to tell exactly what's happening here. But it doesn't look like the result of the "join" is being saved or printed.
jemazar
3,258 PointsStill no pass on 2nd test
for member in musical_groups: members = len(member) ( ', ').join(member) if members == 3: print(member)
OUTPUT ['Ad Rock', 'MCA', 'Mike D.'] ['Salt', 'Peppa', 'Spinderella'] ['Run', 'DMC', 'Jam Master Jay']
AssertionError: 'Ad Rock, MCA, Mike D.' not found in "['Ad Rock', 'MCA', 'Mike D.']\n['Salt', 'Peppa', 'Spinderella']\n['Run', 'DMC', 'Jam Master Jay']" : Hmmm...I'm not getting the output I expected.
Steven Parker
231,248 PointsPlease use this link to learn how to use Markdown formatting to show your code (as I have done below).
But that "join" still isn't being used to help with the printout. You might move it inside the "print":
print((', ').join(member))
Tlotlo Molokwe
16,618 PointsTlotlo Molokwe
16,618 Pointstry: