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 trialFaraz Jahangiri
1,028 Pointswhat is wrong with my code?
I am pretty sure this is the correct syntax or am I wrong?
def hello_student(name):
print('Hello' + name)
1 Answer
boi
14,242 PointsThe challenge wants you to return
the value not print
, also the challenge wants to replicate exactly what has been described anything that does not match, even a missing space or a period is considered a sin by the Gods, and it seems you are missing space in between. a major violation in TreeHouse
def hello_student(name):
return('Hello ' + name) #return and space before the closing comma 'Hello '
Faraz Jahangiri
1,028 Pointsoh right that makes it much clearer. Thank you
Justin Cox
12,123 PointsJustin Cox
12,123 PointsWhile you can technically use this code, it will only work when
name
is guaranteed to be a String. If you pass in an Integer, for example, it will fail saying you cannot concatenate integers with strings.You have a few options for a more pythonic way (and less user-error prone):
Using string interpolation:
Or using F-Strings (only supported in Python 3.6 or higher),
If you absolutely want to stick to using the + sign, you could try casting
name
to a string inside your definition, like so:I hope this helps!