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 trial

Python Python Collections (2016, retired 2019) Lists Combining Lists

"It looks like Task 1 is no longer passing"

Please help? What causes this error?

lists.py
best = [1, 3, "fggs"]
best_ext = best.append(1, 4, 343)

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

What I have learned as a student that the automated grader is not always helpful at letting you know what went wrong in your code if the code contains a syntax error. For example, the code from your first try at the exercise is

best_ext = best.append(1, 4, 343)

This is a syntax error because append will only allow adding one element at a time. But the Code Challenge automated grader will say something to the effect of "Task 1 is no longer passing" which is incorrect, it should have said "Oops there is a syntax error on line 2"

Here is a walkthrough....

Task 1 is simply creating a three element list. Any list elements are acceptable.

best = [1,2,3]

Task 2 is extending the list by two elements. The first line allows it to pass step 1, the second line allows the code to pass task 2

best = [1,2,3]
best += [4,5]

Task 3 is demonstrating a list 'insert', which you are coached to put the string "start" at the beginning of the array or more precisely insert at location zero. The code that accomplishes this task is shown below.

best = [1,2,3]
best += [4,5]
best.insert(0,"start")

If simply putting this code in on each step does not allow you to let the automated grader to pass you, then there may be a browser setting on your own computer that is injecting extra characters or malformed characters into the textboxes of the code challenge.

This would be a question for Treehouse support. (I am just a fellow student, an old guy who likes to help people)

Good luck, learning Python. It will open many possibilities for your career and/or educational goals!

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

The error is caused by using 'best.append(1,4,343)' which is a syntax error, since append only accepts one object and you supplied three integer objects. This causes the Task 1 to fail.

What is being asked in the challenge is to add elements onto the end of the list. There are quite a few different ways to do this -- extend looks like what you were trying to do.

best = [1,2,3]
best.extend(['red','black']) # extending "best" with another list

But, you could also make a list longer by adding on another list

best = [1,2,3]
best += ['red','black'] # a simpler approach of adding one list to another (and assigning the new value to best)

Or, you could make the list longer by .append with two more elements

best = [1,2,3] 
best.append('red') # or the very straight forward approach of appending two times
best.append('black')

Thanks for the assist Jeff, but I'm still getting the same error.