7. strings in functions HELLLLLPPP! what is wrong with my code


#1



when i input this code it says
Oops, try again. string_function('Waynes') returned 'Helloworld' instead of 'Waynesworld'

and it actually prints helloworld but i get that message and when i change it to waynesworld it says i need it to be helloworld


it should print helloworld


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

print string_function(n)


#2

To produce Waynesworld, you'd change "Hello" to "Waynes" here:

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

print string_function(n)

Could you post a screenshot of the error?


#3


#4


#5

see it just goes backwards and forth :cry:


#6

Write a function called string_function that takes in a string argument (s) and then returns that argument concatenated with the word "world". Don't add a space before world!

This should work:

def string_function(s):
    add = s + "world"
    return add
print string_function("Hello")

Notice that I changed the n inside the function, and the content of the parentheses in the last line? Do you understand why I did this and how it works, or would you like an explanation?


#7

no its ok i know why i just did it the other way because it was already there when i started the task so i used n = "hello"


#8

Maybe it was to trick you? :wink:

Yeah, I see how you did that, but remember, it has a parameter for a reason :stuck_out_tongue:


#9

i still get error message:


#10

:cry: nothing will work for me


#11

Try setting the last line to:

print string_function("Waynes")

#12

i just get this error message again and it still prints helloworld


maybe its a glitch on the codecademy website lol.


#13

Could you post the link to the exercise so I can try it please? :slight_smile:


#14

#15

use the argument (s) in return instead of (n) so will be like that:

def string_function(s):
return s +"world"

print string_function(n)

i hope that work


#18