Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Functions, Packing, and Unpacking Getting Info In and Out of Functions Functions with Arguments and Returns

i am so confused about this question dont know whats wrong and what to do next,


def hello_student(name):
    val = name
    return val


1 Answer

The challenge is expecting you to return the string formed by combining 'Hello ' with the value of the parameter name. To combine the strings with string concatenation, you can use + between the strings: 'Hello ' + name. To combine the strings with string interpolation, you could use f'Hello {name}' or 'Hello %s' % name or 'Hello {}'.format(name).

You don't need to call print or assign the value of name to a new variable.

In the line hello_student(hello), hello is treated as a variable, but you haven't defined a value for it, so Python will give you a NameError. To pass the string 'hello' into the function, you would do hello_student('hello'), which should return the string 'Hello hello'.