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 PointsRuns but not right (Python Basic Stage 5)
OK, it runs, but now it's clearly using the indexes and not the actual numbers in the list (as it sums "6" no matter which numbers I insert into "my list"). How do I get it to make that distinction?
my_list = [1,2,3]
def add_list(my_list, total = 0):
for i in range (0, len(my_list)+1):
total = total + i
print "The sum of", my_list, " is ", total
add_list(my_list)
4 Answers
Kenneth Love
Treehouse Guest TeacherHi Nancy. I commented in your most recent thread.
Nancy Melucci
Courses Plus Student 36,143 PointsHi...I am so afraid that Treehouse is going to stop loving me. What a pain in the ass I am. Anyway, I got task 1 to run, but now it's blowing up when I attempt task 2. The code runs in pyCharm and finishes the challenge fine. But it doesn't work here.
Can you help with that? And...because I am a real genuine annoying person, it's in a different place. Let me know if you want me to post the code here. Or just stop.
<
I really want to learn Python.
If that makes any difference.
Nancy M.
Kenneth Love
Treehouse Guest TeacherSo long as you end up learning it, I don't care how many questions you ask. :) I have a 2 year old, so I'm used to tons of questions.
Let's keep it all in one thread, though, OK? That'll make it easier for everyone to keep track of. (and definitely post your new code there)
Nancy Melucci
Courses Plus Student 36,143 PointsJust to try to make life easier, even though that's not my style...this is what I have. It keeps telling me I am missing a positional argument "x"
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
my_list = [1,2,3]
def add_list(my_list):
total = 0
for num in my_list:
total = total + num
return total
x= add_list(my_list)
print(x)
def summarize(my_list,x):
y = str(my_list)
print("The sum of {} is {}.".format(y,x))
summarize(my_list, x)
Nancy Melucci
Courses Plus Student 36,143 PointsYour great mind and my tiny little one working alike...
Kenneth Love
Treehouse Guest TeacherLike I commented in this thread, the summarize()
function is only ever going to be called with one argument, not two. So summarize()
should only have one parameter/argument, my_list
, not two.
You also need to make sure my_list
gets added together and that you return
your string, not print()
it.