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 trial

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

I keep getting Assertion Errors, and string separation issues. What am I doing wrong?

At first, I created the function where basically the "name" variable was added by another string "hello". In the body I created a variable called "greeting", which added the equation of the name variable and "hello" in there respected order.

Secondly, I made the greeting variable be returned, instead of the name.

Thirdly, I made a varible called "greet" to seperate with a split(", ") of the "greeting" variable, to make a third attempt to seperate, while having the "hello" string, and name variable together.

Lastly,  I used a print with the "greet" variable, before I returned it.
*For, the most part, I have print the a string in place of the name variable, when calling my function.
creating_functions.py
def hello_student(name):
    #"hello" + name
    greeting = "hello" + name
    greet = greeting.split(",")
    print(greet)
    return greet
print (hello_student("Luk"))

2 Answers

boi
boi
14,242 Points

Many problems with your code, you're overthinking the challenge, all you need is two lines of code.

def hello_student(name):
    #"hello" + name 👈 (Avoid unnecessary comments or too basic comments)
    greeting = "hello" + name
    greet = greeting.split(",") 👈 # Why do you need to split "greeting" variable?
    print(greet) 👈 #Either use "print" or "return" for cleaner code, also to avoid extra outputs.
    return greet
print (hello_student("Luk"))👈 # While solving challenges, avoid output code lines, the teacher does it for you.

The challenge (task 1) wants you to do 2 basic things; 1) Create a function named hello_student, which takes 1 parameter. 2) It should return the variable Hello plus the parameter, so Hello + parameter.

Spoiler below

def hello_student(parameter):
    return "Hello " + parameter

Thank you! I can't believe I asked such a bad question, all I had to do was capitalize the "H" in the "Hello" string, and return Hello and name. I just figured out the solution right after I asked the question.