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 trialMohd Maqbool Alam
Full Stack JavaScript Techdegree Student 5,715 PointsDoes this solution is right according to the challenge python?
I solve this program by making a list ```x = [1, 2,3]
is this solution is correct according to the problem in challenge.
```functions.py
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.
x = [1, 2, 3]
def add_list(arg1):
total = sum(arg1)
return total
total_sum = add_list(x)
def summarize(arg1):
string_list = str(arg1)
string_con = "The sum of " + string_list + " is " + str(total_sum)
return string_con
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsYour code passes the challenge, but only because the vaidator uses an expected value that you've hardcoded into your code. The challenge is asking you to call the funtion add_list()
directly from summarize()
:
#x = [1, 2, 3] #<-- commented
def add_list(arg1):
total = sum(arg1)
return total
#total_sum = add_list(x) #<-- commented
def summarize(arg1):
string_list = str(arg1)
string_con = "The sum of " + string_list + " is " + str(add_list(arg1)) #<-- Changed
return string_con
Mohd Maqbool Alam
Full Stack JavaScript Techdegree Student 5,715 PointsMohd Maqbool Alam
Full Stack JavaScript Techdegree Student 5,715 Pointsthanks i was getting bad feeling that i hardcoded but i tried to solve the problems over 2 hours