7. Strings in Functions - Python



Says I should display "Waynesworld" when results is "Helloworld."

I expect list N to concatenate with world, not sure where Waynesworld comes from. The results displayed are:

Then it says: Oops, try again. string_function('Waynes') returned 'Helloworld' instead of 'Waynesworld'

When I create a line that prints "Waynesworld" (to troubleshoot why it says waynesworld, not to solve the problem) it says the opposite:

Oops, try again. string_function('Waynes') returned 'Waynesworld' instead of 'Helloworld'

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


inside the function, the parameter (s) is what you pass into the function, so it should be return s + 'world'


no its not work ....


If you have a question, please make your own topic with code + error message + question


no sorry i mean i have that problem too

its not work


and according the guidelines you would have made your own topic

Either way, like i said, inside the function you should use the function argument (s) to join with the "world" string, not the global variable n


I have to say that I'm really didn't understand why it's worked..
why the argument n = s ?


well, when you pass n into the function:

print string_function(n)

The value in n is copied into s (the function parameter, line 3), the advantage of this method, is that you can call the function with different string to join together with world:

print string_function("Greetings")


mmm... ok thanks i thinks i understand it.


I passed, but only after modifying the code in a way I was not instructed. If it wants us to change "n" to "Waynes" instead of "Hello", why doesn't it say so?


Please make a new topic with code with code samples, such questions are too difficult to answer if there is not included.