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 trialPradeep Kamalakannan
1,019 PointsHello, I get an error when I do the below: >>> my_list.append("{}".format(input("Please enter an item: ")))
my_list.append("{}".format(input("Please enter an item: "))) Please enter an item: apple Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module> NameError: name 'apple' is not defined
When I give the input as "apple" with the quotes it works. Should I always use an variable with append ?
2 Answers
Pradeep Kamalakannan
1,019 PointsThanks for the response Michael, The issue I was using python 2.7. input command was not taking parameters as strings. my_list.append() was expecting a string.
The solution was either give the input as "Apple" with quotes or use raw_input which took the value as string.
Michael Nash
3,724 PointsThe problem that you have here is you do not need "{}".format. You only need to use input() in your amend function.
Robert Peters
3,728 Pointsyeah so just: my_list.append(input("Please enter an item: ")) is that not ok?
Lois Shedd
1,126 PointsLois Shedd
1,126 PointsYes, I had the same problem earlier. The videos assume you are using Python 3, so there are some in discrepancies if you are using Python 2 (as installed on Mac by default). This is why I started using the workspaces rather than my own editor.