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 trialNancy Melucci
Courses Plus Student 36,143 PointsStuck on Code Challenge: Python
I want to learn: web design, java, python and as many languages as I can. I get stuck with Python though. I just had to drop a community college course with a (very unfriendly) professor. I got stopped about 3/4 of the way through Kenneth Love's course here before I had that bad experience. SO I am regrouping and trying to finish the basics and go on in the Treehouse sequence. BUT I have to finish Basics first, and I am beginning to despair. I am getting A's in: Java, MySQL and Web Design. So I am not a total idiot. What gives with Python?
Anyway...enough whining. Here's my code for Part 1 of the challenge on which I am stuck. Please and Thank You for the help - I'd really like to learn Python.
add_list = []
new_num = raw_input
def ask_num(raw_input):
print("Enter numbers to add.")
print("Enter DONE to stop inputting numbers")
for item in add_list:
add_list.sum(new_num)
while True:
new_num = input(">")
if new_num == 'DONE':
break
print "The sum of [] is ", add_list()
Nancy Melucci
Courses Plus Student 36,143 PointsI am sorry....obviously the fact I get rattled is part of the problem.
Stage 5 Python Basics.
NJM
Jason Anello
Courses Plus Student 94,610 PointsThis is the code challenge: http://teamtreehouse.com/library/functions-5
Nancy,
For future reference, the easiest way to ask a question about a code challenge is to click on the "Ask a Question" button that's on the challenge page. If you go through the interface there then your question will be automatically linked to the code challenge.
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsIt looks like you're trying to write a complete program here rather than only the function the challenge is asking for.
I recommend that you try to do only what the instructions are asking for and nothing extra.
I'll try to get you started with the skeleton of it along with some tips on what to put inside the function.
Task 1 instructions: Make a function named add_list that adds all of the items in a passed-in list together and returns the total. Assume the list contains only numbers. You'll probably want to use a for loop.
You only have to write a function for task 1.
def add_list(my_list):
#Add your code here
In that code I have made a function named add_list
that will accept a list, my_list
, as an argument.
It suggests that you use a for loop. You can use that to iterate over each number in the list.
You'll probably want to initialize a total
variable to zero. Then inside your loop you can take each number from the list and add it to total
. When you're all done looping you can then return total
See what you can come up with and let us know if you're having any problems.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Nancy,
Which code challenge is this from?