Strings in functions


#1

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

print string_function(s)

Can anyone tell me what is wrong with this? this is the error code i get
Oops, try again. string_function('Waynes') returned 'Helloworld' instead of 'Waynesworld'

I do not see anything about "Wayne" in the directions.


#2

You really ought to do this

n = "Hello"
def string_function(n):
    return n+" world"

print string_function(n)

#3
n = "Hello"
def string_function(n):
       s = "Hello" +"world"       # here you have assigned a fixed value to s i.e "Helloworld"
       return s                     so when the argument *s* changes to "Wayne"  your code then also
                                    prints "Helloworld"  insted of 'Waynesworld'
print string_function(s)

improve your code to

n = "Hello"
def string_function(s):
    return s+'world'                 # here argument *s* changes accordingly