7. Strings in Functions


#1


Lists and Functions > Strings in Functions

Error .. returns 'Helloworld' instead of 'Waynesworld'

If I change "Hello" to "Waynes" the error reads that it returns 'Waynesworld' instead of 'Helloworld'

It is supposed to print 'Helloworld'


n = "Hello"
# Your function here!

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

print string_function(n)

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


#2

UPDATE

n = "Hello"

Your function here!

def string_function(n): <--- FIXED HERE, but I don't understand if someone could explain
s = n + "world";
return s

print string_function(n)


#3

You needed your function parameter to match in your print and in your definition. In you first code you had s as a parameter in your definition and n as a paramater in your print statement. So once you made them jive by replacing both to n your function didn't have conflicting parameters anymore and ran the code fine. However, just glancing back at the instructions it probably wanted s to be used as the argument as stated in first part of the instruction paragraph.


#4

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