Strings in function error


#1

I'm pretty sure there is something wrong with this outside of my code. The error I get says its looking for "Waynesworld" instead of "Helloworld". I've used both variations of the code below and get the same error message.


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

print string_function(n)


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

print string_function(n)


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


#2

Your first answer is closer. The reason that they're looking for Waynesworld is because they input 'Waynes' and are expecting it to be added to the string "world", the reason your code is wrong is because you say

when you want to return s + world, (s is the argument passed, such as the string held in n or 'Waynes')
Does this make sense? You want a function that returns whatever is passed into the function plus "world"


#3

Kyleaw,

Thank you, I see what you mean. I was trying to call n from outside the function when it was already inside the function as s.

Appreciate it


#4

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