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 trialTanzila Rafeeq
2,936 Pointswhats wrong
def unpacker(val1, val2):
return val1 + " " + val2
val = unpacker('Python', 'rocks!')
print(val1)
print(val2)
2 Answers
jb30
44,806 PointsYou have set val1
and val2
as parameters in your function, but they haven't been defined outside the function. This will give a NameError when you try to print their values.
The challenge wants you to edit the variable assignment. You don't need to modify the function or the function call. The provided function returns a tuple.
If you have a tuple such as ("Python", "Rocks")
, you can use it to assign values to multiple variables at once using the form val1, val2 = ("Python", "Rocks")
as long as the number of variables that you are assigning values to is equal to the size of the tuple that you are getting the values from.
Victor Curtis Jr
5,268 PointsIf I could give you one word for this code challenge: simplify. You kinda went overboard on this by changing the return value to val1 + " " + val2
. You don't need to do that. Everything can basically be kept the same. Go back and look at the video for how the instructor called two variables. It might make a lot more sense then. Hint: val = unpacker('Python', 'rocks!')
this is still only calling one variable. How do you call two?