7. Wayne's world error?



So this is the error message I get: Oops, try again. string_function('Waynes') returned 'Helloworld' instead of 'Waynesworld'

User error?

n = "Hello"
# Your function here!
def string_function(s):
    return n+s

print string_function(n)


Hello @hackz0r,

The error you are making is that you are setting the value of the argument passed into the function to "world" and then concatenating it with the string n. Since n isn't a local variable defined inside of the function, python immediately looks for a global variable n, and finds it to contain the string Hello. So, what you are actually returning in this function is

return n+s
return n("Hello") + s("world")

What you should instead be doing is passing in an argument (lets call it s), and concatenating it with a variable containing the string "world" or the string "world" itself, and returning that value...


Ya, that didn't really help me. I don't know how to do that or how that would be different from what I've already done


To correctly execute your code you would need a space in the n variable like this,

n = "Hello " #Note the space after hello

And your return statement is trying to return the global variable n + the local variable s to do so your function cannot have an argument thus not allowing you to pass the excercise.

Meaning to for your code to correctly execute you would need to follow the instructions explicitly as in, if I wanted to return Hello World in my function I would add s + the string 'world' :slight_smile:

return s + 'world'


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.