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 trialTony Andre Haugen
2,807 PointsGetting the right answer locally but not on the code challenge.
Hi,
This has happened so many times now that I had to ask. I get the correct answer locally when running my code - but when I get onto treehouse and submit my code I get "Bummer! Try again!".
For example:
def combo(a, b):
my_tuple_list = []
for k, v in enumerate(a):
my_tuple_list.append((v, b[k]))
print(my_tuple_list)
combo([1, 2, 3], 'abc')
gives me:
python zippy.py
[(1, 'a'), (2, 'b'), (3, 'c')]
locally which should be correct judging by the commented section on the challenge. But I still get a bummer.
Why?
Thanks.
3 Answers
Cody Te Awa
8,820 PointsHey Tony, You've done a great job with it, you just need to return my_tuple_list instead of printing it out at the end of your function! Keep up the good work! Happy coding! :) -CodyTheCoder
Kristian Gausel
14,661 PointsLike Cody says, you need to return the value in the function, not just print it out. I suggest trying/doing this locally instead, so you can grasp the differences of returning and printing:
def combo(a, b):
my_tuple_list = []
for k, v in enumerate(a):
my_tuple_list.append((v, b[k]))
return my_tuple_list
print(combo([1, 2, 3], 'abc'))
Tony Andre Haugen
2,807 PointsHahaha, oh my god! Thanks guys for clearing it up - I have been doing coding challenges @ hackerrank for the whole day and night so things went kind of south from there :\ Been sleeping a bit now - so going back at it :D
And I do know the difference; this was just my eyes playing a trick on me :\ Thanks for the answers guys :)
The only reason I give Cody the "Best Answer" is that he was first :) Love the example tho, Kristian :)