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

Luke Tate
PLUS
Luke Tate
Courses Plus Student 2,243 Points

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

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
Luke Tate
PLUS
Luke Tate
Courses Plus Student 2,243 Points

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.