7. Strings in Functions - Python


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/1/3?curriculum_id=4f89dab3d788890003000096#

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:
Helloworld
None

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)


#2

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


#3

no its not work ....


#4

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


#5

no sorry i mean i have that problem too



its not work


#6

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


#7

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


#8

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")

#9

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


#10

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?


#11

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